STDGRID

Top  Previous  Next

unit StDGrid;

 

interface

 

uses

SysUtils, WinTypes, WinProcs, Messages, Classes, Menus, Szamok,

Graphics, Controls, Forms, Dialogs, StMap16, StMap161, Grids, AlmType;

 

type

{Mely adatok mutatkozzonak az adattáblában?}

TDataGridFilterType = (dgtAll,dgtFiltered);

{Csak látható, csak aktív réteg, töröltek is, kijelöltek is}

TDataGridFiltered = (dFiltVisible,dFiltActLayer,dFiltDeleted,dFiltSigned);

TDataGridFilteredSet = set of TDataGridFiltered;

 

TRecType = (rtPont,rtVonal,rtFelirat,rtJelkulcs);

TRecordEvent = procedure(Sender: TObject; No:integer; AktPos : longint; var Rec) of object;

TRecordMoveEvent = procedure(Sender: TObject; No:integer; AktPos : longint; var Rec) of object;

 

TSTDataGrid = class(TStringGrid)

private

  mi   : Array[0..7] of TMenuItem;

  pR        : TPontrecord;

  vR        : TVonalrecord;

  fR        : TSzovegrecord;

  jR        : TJelkulcsrecord;

  Faktpont : Longint;

  Faktvonal : Longint;

  FaktFelirat : Longint;

  Faktjelkulcs : Longint;

  FDataVisibility : TDataGridFilterType;      {Minden, vagy szűrt elemek}

  FDataFilter : TDataGridFilteredSet;         {adattáblában megjelenő elemek}

  FPontRec : TPontrecord;

  FVonalRec : TVonalrecord;

  FFeliratRec : TSzovegrecord;

  FJelkulcsRec : TJelkulcsrecord;

  FRecType : TRecType;

  FReszletes: boolean;           {A jelzők bitlistája nyitva}

  FStellaMapSource : TStellaMap;

  FMapFile : string;

  FCanModify : boolean;

  FSelecTedColor : TColor;

  FUnSelecTedColor : TColor;

  FOnBeforeNewRec : TRecordEvent;

  FOnAfterNewRec : TRecordEvent;

  FOnRecordMove  : TRecordMoveEvent;

  FActiveSearch : boolean;              {A StellaMap-en folyamatos követés}

  procedure SetDataVisibility(Value:TDataGridFilterType);

  procedure SetDataFilter(Value:TDataGridFilteredSet);

  procedure SetPontRec(Value:TPontrecord);

  procedure SetVonalRec(Value:TVonalrecord);

  procedure SetFeliratRec(Value:TSzovegrecord);

  procedure SetJelkulcsRec(Value:TJelkulcsrecord);

  procedure SetRecType(Value:TRecType);

  procedure SetReszletes(Value: boolean);

  procedure SetStellaMapSource(Value:TStellaMap);

  procedure SetMapFile(Value:string);

  procedure SetCanModify(Value:boolean);

  procedure SetSelecTedColor(Value:TColor);

  procedure SetUnSelecTedColor(Value:TColor);

  procedure Setaktpont(Value:longint);

  procedure SetaktVonal(Value:longint);

  procedure SetaktFelirat(Value:longint);

  procedure SetaktJelkulcs(Value:longint);

  procedure SetActiveSearch(Value : boolean);

{    procedure PMenuPopup(Sender: TObject);

  procedure PMenuOnClick(Sender: TObject);}

protected

  Direction : integer;           {>0 előre; <0 visszafelé keres}

  oldPRec   : TPontrecord;

  oldVRec   : TVonalrecord;

  oldSzRec  : TSzovegrecord;

  oldJRec   : TJelkulcsrecord;

  ujElem    : boolean;

  ujrec     : boolean;

  procedure GridInit;

  procedure PontGridFeltolt;dynamic;

  procedure VonalGridFeltolt;dynamic;

  procedure FeliratGridFeltolt;dynamic;

  procedure JelkulcsGridFeltolt;dynamic;

  function  FirstPont:TPontRecord;

  function  PriorPont:TPontRecord;

  function  NextPont:TPontRecord;

  function  LastPont:TPontRecord;

  function  FirstVonal:TVonalRecord;

  function  PriorVonal:TVonalRecord;

  function  NextVonal:TVonalRecord;

  function  LastVonal:TVonalRecord;

  function  FirstFelirat:TSzovegRecord;

  function  PriorFelirat:TSzovegRecord;

  function  NextFelirat:TSzovegRecord;

  function  LastFelirat:TSzovegRecord;

  function  FirstJelkulcs:TJelkulcsRecord;

  function  PriorJelkulcs:TJelkulcsRecord;

  function  NextJelkulcs:TJelkulcsRecord;

  function  LastJelkulcs:TJelkulcsRecord;

  Procedure Paint;override;

  procedure Notification(AComponent: TComponent;

    Operation: TOperation); override;

  procedure OnSearch(Sender: TObject; No:integer; AktPos : longint; var Rec);

  procedure OnNewMapFile(Sender: TObject; NewMapFile: string);

  procedure MouseDown(Button: TMouseButton; Shift: TShiftState;

    X, Y: Integer); override;

  procedure KeyPress(var Key: Char); override;

  function SelectCell(Col, Row: Longint):boolean; override;

public

  fStream   : TFileStream;

  valtozott : boolean;

{    PMenu     : TPopupMenu;}

  constructor Create(AOwner:TComponent);override;

  destructor Destroy;override;

  Property aktpont : Longint read Faktpont write Setaktpont;       {Aktuális pont sorszáma}

  Property aktvonal : Longint read Faktvonal write Setaktvonal;

  Property aktFelirat : Longint read FaktFelirat write SetaktFelirat;

  Property aktjelkulcs : Longint read Faktjelkulcs write Setaktjelkulcs;

  Property PontRec : TPontrecord read FPontRec write SetPontRec ;

  Property VonalRec : TVonalrecord read FVonalRec write SetVonalRec ;

  Property FeliratRec : TSzovegrecord read FFeliratRec write SetFeliratRec ;

  Property JelkulcsRec : TJelkulcsrecord read FJelkulcsRec write SetJelkulcsRec ;

  Procedure Execute;

  Function SaveFile(MapFile:string) : boolean;

  Function LoadFile(MapFile:string) : boolean;

  Procedure TablaFeltolt;

  procedure Pontfeltoltes(p:TPontRecord);

  procedure Vonalfeltoltes(p:TVonalRecord);

  procedure Feliratfeltoltes(p:TSzovegRecord);

  procedure Jelkulcsfeltoltes(p:TJelkulcsRecord);

  Function Pontkinyeres:TPontRecord;

  Function Vonalkinyeres:TVonalRecord;

  Function Feliratkinyeres:TSzovegRecord;

  Function Jelkulcskinyeres:TJelkulcsRecord;

  function NewPont:TPontRecord;

  function NewVonal:TVonalRecord;

  function NewFelirat:TSzovegRecord;

  function NewJelkulcs:TJelkulcsRecord;

  procedure SavePont(p:TPontRecord);

  procedure SaveVonal(p:TVonalRecord);

  procedure SaveFelirat(p:TSzovegRecord);

  procedure SaveJelkulcs(p:TJelkulcsRecord);

  function  IsFilter(var rec):boolean;

  function  GetPontRec(pos:longint):TPontRecord;

  function  GetVonalRec(pos:longint):TVonalRecord;

  function  GetFeliratRec(pos:longint):TSzovegRecord;

  function  GetJelkulcsRec(pos:longint):TJelkulcsRecord;

  function  GetRecSzam(No: longint):longint;

  procedure First;

  procedure Prior;

  procedure Next;

  procedure Last;

  procedure Cancel;

  procedure New;

  procedure Save;

  procedure Delete;

  procedure MapReDraw;

published

  Property StellaMapSource : TStellaMap read FStellaMapSource write SetStellaMapSource ;

  Property ActiveSearch : boolean read FActiveSearch write SetActiveSearch;

  Property DataVisibility : TDataGridFilterType read FDataVisibility write SetDataVisibility;

  Property DataFilter : TDataGridFilteredSet read FDataFilter write SetDataFilter;

  Property MapFile : string read FMapFile write SetMapFile ;

  Property CanModify : boolean read FCanModify write SetCanModify ;

  Property RecType : TRecType read FRecType write SetRecType ;

  Property Reszletes: boolean read FReszletes write SetReszletes;

  Property SelecTedColor : TColor read FSelecTedColor write SetSelecTedColor;

  Property UnSelecTedColor : TColor read FUnSelecTedColor write SetUnSelecTedColor;

  Property OnBeforeNewRec : TRecordEvent read FOnBeforeNewRec write FOnBeforeNewRec ;

  Property OnAfterNewRec : TRecordEvent read FOnAfterNewRec write FOnAfterNewRec ;

  Property OnRecordMove : TRecordMoveEvent read FOnRecordMove write FOnRecordMove;

  property OnClick;

end;

 

procedure Register;

 

implementation

 

Const mCaptiom : Array[0..7] of String[13] = ('Törölt','Zárolt','Spec. jelölt',

             'Nem használt','SQL Filter','Módosított','Új elem','Kijelölt');

 

procedure Register;

begin

   RegisterComponents('StellaMap',[TSTDataGrid]);

end;

 

constructor TSTDataGrid.Create(AOwner:TComponent);

var i: integer;

begin

   inherited Create(AOwner);

   FStellaMapSource := nil;

   Width:=155; Height:=223;

   DefaultColWidth := 50; Colwidths[1]:=100;

   DefaultRowHeight := 16;

   SelecTedColor := clWhite;

   UnSelecTedColor := clSilver;

   FixedCols := 1;

   FixedRows := 1;

   ColCount := 2;

   Font.Name := 'Arial'; Font.Size := 8; Font.Style := [];

   CanModify := False; Color := clSilver;

   FRecType := rtPont;

   Options:=Options+[goColSizing];

   valtozott := False;

{     PMenu     := TPopupMenu.Create(Self);

   For i:=0 to 7 do begin

       mi[i] := TMenuItem.Create(PMenu);

       mi[i].Name := 'JELZO'+IntToStr(i);

       mi[i].Caption := mCaptiom[i];

       mi[i].Enabled := True;

       PMenu.Items.Add(mi[i]);

       PMenu.OnPopup:=PMenuPopup;

   end;}

   Reszletes:=False;

   direction := 1;

   GridInit;

{     PontGridFeltolt;}

end;

 

destructor TSTDataGrid.Destroy;

begin

   if fStream<>nil then fStream.Destroy;

{     PMenu.Free;}

   inherited Destroy;

end;

 

procedure TSTDataGrid.SetDataVisibility(Value:TDataGridFilterType);

begin

If FDataVisibility<>Value then begin

   FDataVisibility:=Value;

   invalidate;

end;

end;

 

procedure TSTDataGrid.SetDataFilter(Value:TDataGridFilteredSet);

begin

If FDataFilter<>Value then begin

   FDataFilter:=Value;

   invalidate;

end;

end;

 

function TSTDataGrid.SelectCell(Col, Row: Longint):boolean;

var t:TRect; p:TPoint;

begin

 inherited SelectCell(Col,Row);

 If Cells[0,Row]='Jelző' then begin

    If not reszletes then Reszletes:=True

 end else begin

     If reszletes and (Row<RowCount-8) then Reszletes:=False;

 end;

 Result:=True;

end;

 

Procedure TSTDataGrid.Execute;

begin

If FStellaMapSource<>nil then begin

   AktPont := StellaMapSource.tm[1].Position-SizeOf(TPontrecord);

   AktVonal := StellaMapSource.tm[2].Position-SizeOf(TVonalrecord);

   AktFelirat := StellaMapSource.tm[3].Position-SizeOf(TSzovegrecord);

   AktJelkulcs := StellaMapSource.tm[4].Position-SizeOf(TJelkulcsrecord);

end else if MapFile<>'' then begin

end;

   Case RecType of

   rtPont    : Pontfeltoltes(PontRec);

   rtVonal   : Vonalfeltoltes(VonalRec);

   rtFelirat : Feliratfeltoltes(FeliratRec);

   rtJelkulcs: Jelkulcsfeltoltes(JelkulcsRec);

   end;

GridInit;

end;

 

procedure TSTDataGrid.SetReszletes(Value: boolean);

begin

If FReszletes<>Value then begin

FReszletes:=Value;

GridInit;

invalidate;

end;

end;

 

procedure TSTDataGrid.Setaktpont(Value:longint);

var pr: TPontrecord;

begin

Faktpont:=Value; PontRec:=GetPontRec(Value); pr:=PontRec;

Cells[1,0]:=Inttostr(Value+1)+'/'+Inttostr(GetRecSzam(1));

If Assigned(FOnRecordMove) then FOnRecordMove(Self,1,Value,pr);

invalidate;

end;

 

procedure TSTDataGrid.SetaktVonal(Value:longint);

var vr: TVonalrecord;

begin

FaktVonal:=Value; VonalRec := GetVonalRec(Value); vr:=VonalRec;

Cells[1,0]:=Inttostr(Value+1)+'/'+Inttostr(GetRecSzam(2));

If Assigned(FOnRecordMove) then FOnRecordMove(Self,2,Value,vr);

invalidate;

end;

 

procedure TSTDataGrid.SetaktFelirat(Value:longint);

var sr: TSzovegrecord;

begin

FaktFelirat:=Value; FeliratRec := GetFeliratRec(Value); sr:=FeliratRec;

Cells[1,0]:=Inttostr(Value+1)+'/'+Inttostr(GetRecSzam(3));

If Assigned(FOnRecordMove) then FOnRecordMove(Self,3,Value,sr);

invalidate;

end;

 

procedure TSTDataGrid.SetaktJelkulcs(Value:longint);

var jr: TJelkulcsrecord;

begin

FaktJelkulcs:=Value; JelkulcsRec := GetJelkulcsRec(Value);  jr:=JelkulcsRec;

Cells[1,0]:=Inttostr(Value+1)+'/'+Inttostr(GetRecSzam(4));

If Assigned(FOnRecordMove) then FOnRecordMove(Self,4,Value,jr);

invalidate;

end;

 

procedure TSTDataGrid.SetPontRec(Value:TPontrecord);

begin

FPontRec:=Value;

Pontfeltoltes(Value);

PR:=Value;

end;

 

 

procedure TSTDataGrid.SetVonalRec(Value:TVonalrecord);

begin

FVonalRec:=Value;

Vonalfeltoltes(Value); VR:=Value;

end;

 

 

procedure TSTDataGrid.SetFeliratRec(Value:TSzovegrecord);

begin

FFeliratRec:=Value;

Feliratfeltoltes(Value); FR:=Value;

end;

 

 

procedure TSTDataGrid.SetJelkulcsRec(Value:TJelkulcsrecord);

begin

FJelkulcsRec:=Value;

Jelkulcsfeltoltes(Value); JR:=Value;

end;

 

procedure TSTDataGrid.SetRecType(Value:TRecType);

begin

   Case Value of

   rtPont    : begin PontGridFeltolt;AktPont:=AktPont;end;

   rtVonal   : begin VonalGridFeltolt;AktVonal:=AktVonal;end;

   rtFelirat : begin FeliratGridFeltolt;AktFelirat:=AktFelirat;end;

   rtJelkulcs: begin JelkulcsGridFeltolt;AktJelkulcs:=AktJelkulcs;end;

   end;

   FRecType:=Value;

   invalidate;

end;

 

procedure TSTDataGrid.SetActiveSearch(Value : boolean);

begin

FActiveSearch:=Value;

valtozott := Value;

invalidate;

end;

 

procedure TSTDataGrid.SetStellaMapSource(Value:TStellaMap);

begin

If FStellaMapSource<>Value then begin

   FStellaMapSource:=Value;

   FStellaMapSource.OnSearch:=OnSearch;

   FStellaMapSource.OnNewMapfile := OnNewMapFile;

   If FMapFile<>'' then begin

      FMapFile:='';

      fStream.Free;

   end;

   AktPont:=0; AktVonal:=0; AktFelirat:=0; AktJelkulcs:=0;

   GridInit;

end;

end;

 

 

procedure TSTDataGrid.SetMapFile(Value:string);

begin

If FMapFile<>Value then begin

   FMapFile:=Value;

   If StellaMapSource=Nil then

   begin

     If FileExists(Value) then

        fStream := TFileStream.Create(Value,fmShareExclusive)

     else

        fStream := TFileStream.Create(Value,fmCreate);

   end

   else if fStream<>nil then

      fStream.Destroy;

   AktPont:=0; AktVonal:=0; AktFelirat:=0; AktJelkulcs:=0;

   GridInit;

end;

end;

 

procedure TSTDataGrid.SetCanModify(Value:boolean);

begin

If FCanModify<>Value then begin

   FCanModify:=Value;

   If FCanModify then begin

      Color:=SelecTedColor;

      If not (goEditing in Options) then Options:=Options+[goEditing];

   end else begin

      Color:=UnSelecTedColor;

      If (goEditing in Options) then Options:=Options-[goEditing];

   end;

   invalidate;

end;

end;

 

procedure TSTDataGrid.SetSelecTedColor(Value:TColor);

begin

FSelecTedColor:=Value;

Color:=Value;

Invalidate;

end;

 

procedure TSTDataGrid.SetUnSelecTedColor(Value:TColor);

begin

FUnSelecTedColor:=Value;

Color:=Value;

Invalidate;

end;

 

Function TSTDataGrid.SaveFile(MapFile:string) : boolean;

begin

 

end;

 

Function TSTDataGrid.LoadFile(MapFile:string) : boolean;

begin

If StellaMapSource<>Nil then StellaMapSource.MapFile:=MapFile;

end;

 

procedure TSTDataGrid.PontGridFeltolt;

Var   i : integer;

Const rFelirat: Array[1..9] of String = ('Réteg','Sorszám','X','Y','Z',

              'Pontkód','Infó','Obj','Jelző');

begin

ColWidths[0]:=80;

If not reszletes then RowCount:=10 else RowCount:=18;

Cells[0,0]:='Pont'; AktPont:=AktPont;

For i:=1 to 9 do Cells[0,i]:=rFelirat[i];Cells[1,i]:='';

If Reszletes then For i:=0 to 7 do Cells[0,i+10]:=' - '+mCaptiom[i]

end;

 

procedure TSTDataGrid.VonalGridFeltolt;

Var   i : integer;

Const rFelirat: Array[1..12] of String = ('Réteg','X1','Y1','Z1','X2','Y2','Z2',

              'Vastag','Tipus','Obj1','Obj2','Jelző');

begin

ColWidths[0]:=80;

If not reszletes then RowCount:=13 else RowCount:=21; AktVonal:=AktVonal;

Cells[0,0]:='Vonal';

For i:=1 to 12 do Cells[0,i]:=rFelirat[i];Cells[1,i]:='';

If Reszletes then For i:=0 to 7 do Cells[0,i+13]:=' - '+mCaptiom[i]

end;

 

procedure TSTDataGrid.FeliratGridFeltolt;

Var   i : integer;

Const rFelirat: Array[1..11] of String = ('Réteg','X','Y','Községkód','Felirat',

              'Font','Széles','Stílus','Szög','Obj','Jelző');

begin

ColWidths[0]:=80;

If not reszletes then RowCount:=12 else RowCount:=20;

Cells[0,0]:='Felirat'; AktFelirat:=AktFelirat;

For i:=1 to 11 do Cells[0,i]:=rFelirat[i];Cells[1,i]:='';

If Reszletes then For i:=0 to 7 do Cells[0,i+12]:=' - '+mCaptiom[i]

end;

 

procedure TSTDataGrid.JelkulcsGridFeltolt;

Var   i : integer;

Const rFelirat: Array[1..8] of String = ('Kód','Réteg','X','Y',

              'Méret','Szög','Obj','Jelző');

begin

ColWidths[0]:=80;

If not reszletes then RowCount:=9 else RowCount:=17;

Cells[0,0]:='Jelkulcs'; AktJelkulcs:=AktJelkulcs;

For i:=1 to 8 do Cells[0,i]:=rFelirat[i];Cells[1,i]:='';

If Reszletes then For i:=0 to 7 do Cells[0,i+9]:=' - '+mCaptiom[i]

end;

 

procedure TSTDataGrid.Notification(AComponent: TComponent;

Operation: TOperation);

begin

inherited Notification(AComponent, Operation);

if (Operation = opRemove) and (AComponent = StellaMapSource)

then StellaMapSource := nil;

end;

 

 

Procedure TSTDataGrid.TablaFeltolt;

begin

   Case RecType of

   rtPont    : Pontfeltoltes(PontRec);

   rtVonal   : Vonalfeltoltes(VonalRec);

   rtFelirat : Feliratfeltoltes(FeliratRec);

   rtJelkulcs: Jelkulcsfeltoltes(JelkulcsRec);

   end;

end;

 

procedure TSTDataGrid.Pontfeltoltes(p:TPontRecord);

var i:integer;

begin

If (StellaMapSource=nil) then p:=NewPont

else if (StellaMapSource.tm[1].Size=0) then p:=NewPont;

  Cells[1,1]:=InttoStr(p.reteg);

  Cells[1,2]:=InttoStr(p.No);

  Cells[1,3]:=FloatToStr(p.x);

  Cells[1,4]:=FloatToStr(p.y);

  Cells[1,5]:=FloatToStr(p.z);

  Cells[1,6]:=InttoStr(p.pkod);

  Cells[1,7]:=InttoStr(p.info);

  Cells[1,8]:=InttoStr(p.obj);

  Cells[1,9]:=Copy(DecToBin(p.jelzo),9,8);

  For i:=0 to 7 do Cells[1,10+i]:=InttoStr(GetBit(p.jelzo,i));

  Update;

end;

 

procedure TSTDataGrid.Vonalfeltoltes(p:TVonalRecord);

var i:integer;

begin

If (StellaMapSource=nil) then p:=NewVonal

else if (StellaMapSource.tm[2].Size=0) then p:=NewVonal;

  Cells[1,1]:=InttoStr(p.reteg);

  Cells[1,2]:=FloatToStr(p.x1);

  Cells[1,3]:=FloatToStr(p.y1);

  Cells[1,4]:=FloatToStr(p.z1);

  Cells[1,5]:=FloatToStr(p.x2);

  Cells[1,6]:=FloatToStr(p.y2);

  Cells[1,7]:=FloatToStr(p.z2);

  Cells[1,8]:=InttoStr(p.vastag);

  Cells[1,9]:=InttoStr(p.tipus);

  Cells[1,10]:=InttoStr(p.obj1);

  Cells[1,11]:=InttoStr(p.obj2);

  Cells[1,12]:=Copy(DecToBin(p.jelzo),9,8);

  For i:=0 to 7 do Cells[1,13+i]:=InttoStr(GetBit(p.jelzo,i));

end;

 

procedure TSTDataGrid.Feliratfeltoltes(p:TSzovegRecord);

var i:integer;

begin

If (StellaMapSource=nil) then p:=NewFelirat

else if (StellaMapSource.tm[3].Size=0) then p:=NewFelirat;

  Cells[1,1]:=InttoStr(p.reteg);

  Cells[1,2]:=FloatToStr(p.x);

  Cells[1,3]:=FloatToStr(p.y);

  Cells[1,4]:=Inttostr(p.kozsegkod);

  Cells[1,5]:=p.szoveg;

  Cells[1,6]:=IntToStr(p.font);

  Cells[1,7]:=IntToStr(p.szeles);

  Cells[1,8]:=InttoStr(p.stilus);

  Cells[1,9]:=InttoStr(p.szog);

  Cells[1,10]:=InttoStr(p.obj);

  Cells[1,11]:=Copy(DecToBin(p.jelzo),9,8);

  For i:=0 to 7 do Cells[1,12+i]:=InttoStr(GetBit(p.jelzo,i));

end;

 

procedure TSTDataGrid.Jelkulcsfeltoltes(p:TJelkulcsRecord);

var i:integer;

begin

If (StellaMapSource=nil) then p:=NewJelkulcs

else if (StellaMapSource.tm[4].Size=0) then p:=NewJelkulcs;

  Cells[1,1]:=InttoStr(p.kod);

  Cells[1,2]:=InttoStr(p.reteg);

  Cells[1,3]:=FloatToStr(p.x);

  Cells[1,4]:=FloatToStr(p.y);

  Cells[1,5]:=InttoStr(p.meret);

  Cells[1,6]:=InttoStr(p.szog);

  Cells[1,7]:=InttoStr(p.obj);

  Cells[1,8]:=Copy(DecToBin(p.jelzo),9,8);

  For i:=0 to 7 do Cells[1,9+i]:=InttoStr(GetBit(p.jelzo,i));

end;

 

Function TSTDataGrid.Pontkinyeres:TPontRecord;

var i:integer;

begin

  oldPRec := PontRec;

  Result.reteg := StrToInt(Cells[1,1]);

  Result.No    := StrToInt(Cells[1,2]);

  Result.x     := StrToFloat(Cells[1,3]);

  Result.y     := StrToFloat(Cells[1,4]);

  Result.z     := StrToFloat(Cells[1,5]);

  Result.pkod  := StrToInt(Cells[1,6]);

  Result.info  := StrToInt(Cells[1,7]);

  Result.obj   := StrToInt(Cells[1,8]);

  If reszletes then begin

     Cells[1,9]:='';

     For i:=0 to 7 do Cells[1,9]:=Cells[1,10+i]+Cells[1,9];

  end;

  Result.jelzo := BinToDec(Cells[1,9]);

end;

 

Function TSTDataGrid.Vonalkinyeres:TVonalRecord;

var i:integer;

begin

  oldVRec := VonalRec;

  Result.reteg := StrToInt(Cells[1,1]);

  Result.x1    := StrToFloat(Cells[1,2]);

  Result.y1    := StrToFloat(Cells[1,3]);

  Result.z1    := StrToFloat(Cells[1,4]);

  Result.x2    := StrToFloat(Cells[1,5]);

  Result.y2    := StrToFloat(Cells[1,6]);

  Result.z2    := StrToFloat(Cells[1,7]);

  Result.vastag:= StrToInt(Cells[1,8]);

  Result.tipus := StrToInt(Cells[1,9]);

  Result.obj1  := StrToInt(Cells[1,10]);

  Result.obj2  := StrToInt(Cells[1,11]);

  If reszletes then begin

     Cells[1,12]:='';

     For i:=0 to 7 do Cells[1,12]:=Cells[1,13+i]+Cells[1,12];

  end;

  Result.jelzo := BinToDec(Cells[1,12]);

end;

 

Function TSTDataGrid.Feliratkinyeres:TSzovegRecord;

var i:integer;

begin

  oldSzRec := FeliratRec;

  Result.reteg := StrToInt(Cells[1,1]);

  Result.x     := StrToFloat(Cells[1,2]);

  Result.y     := StrToFloat(Cells[1,3]);

  Result.kozsegkod := StrToInt(Cells[1,4]);

  Result.szoveg:= Cells[1,5];

  Result.font  := StrToInt(Cells[1,6]);

  Result.szeles:= StrToInt(Cells[1,7]);

  Result.stilus:= StrToInt(Cells[1,8]);

  Result.szog  := StrToInt(Cells[1,9]);

  Result.obj   := StrToInt(Cells[1,10]);

  If reszletes then begin

     Cells[1,11]:='';

     For i:=0 to 7 do Cells[1,11]:=Cells[1,12+i]+Cells[1,11];

  end;

  Result.jelzo := BinToDec(Cells[1,11]);

end;

 

Function TSTDataGrid.Jelkulcskinyeres:TJelkulcsRecord;

var i:integer;

begin

  oldJRec := JelkulcsRec;

  Result.kod   := StrToInt(Cells[1,1]);

  Result.reteg := StrToInt(Cells[1,2]);

  Result.x     := StrToFloat(Cells[1,3]);

  Result.y     := StrToFloat(Cells[1,4]);

  Result.meret := StrToInt(Cells[1,5]);

  Result.szog  := StrToInt(Cells[1,6]);

  Result.obj   := StrToInt(Cells[1,7]);

  If reszletes then begin

     Cells[1,8]:='';

     For i:=0 to 7 do Cells[1,8]:=Cells[1,9+i]+Cells[1,8];

  end;

  Result.jelzo := BinToDec(Cells[1,8]);

end;

 

Procedure TSTDataGrid.Paint;

begin

If (FStellaMapSource<>nil) and ActiveSearch and valtozott then

   MapReDraw;

inherited Paint;

end;

 

procedure TSTDataGrid.MapReDraw;

var x,y: double;

begin

If (FStellaMapSource<>nil) then begin

   Case RecType of

   rtPont    : begin x:=PontRec.x; y:=PontRec.y;end;

   rtVonal   : begin x:=(VonalRec.x1+VonalRec.x2)/2;

                     y:=(VonalRec.y1+VonalRec.y2)/2;

               end;

   rtFelirat : begin x:=FeliratRec.x; y:=FeliratRec.y; end;

   rtJelkulcs: begin x:=JelkulcsRec.x; y:=JelkulcsRec.y; end;

   end;

   FStellaMapSource.Centrumx:=x;

   FStellaMapSource.Centrumy:=y;

   valtozott := False;

end;

end;

 

procedure TSTDataGrid.OnSearch(Sender: TObject; No:integer; AktPos : longint; var Rec);

{Ha a TStellaMap-en eredményes keresés történt}

begin

   Case No of

   1 : begin

            AktPont := AktPos;

            PontRec:=StellaMapSource.PontRec;

       end;

   2 : begin

            AktVonal := AktPos;

            VonalRec:=StellaMapSource.VonalRec;

       end;

   3 : begin

            AktFelirat := AktPos;

            FeliratRec:=StellaMapSource.FeliratRec;

       end;

   4 : begin

            AktJelkulcs := AktPos;

            JelkulcsRec:=StellaMapSource.JelkulcsRec;

       end;

   end;

   valtozott := True;

   RecType := TRecType(No-1);

end;

 

procedure TSTDataGrid.OnNewMapFile(Sender: TObject; NewMapFile: string);

begin

MapFile := NewMapFile;

end;

 

  function TSTDataGrid.NewPont:TPontRecord;

  begin

       FillChar(Result,SizeOf(Result),0);

  end;

 

  function TSTDataGrid.NewVonal:TVonalRecord;

  begin

       FillChar(Result,SizeOf(Result),0);

  end;

 

  function TSTDataGrid.NewFelirat:TSzovegRecord;

  begin

       FillChar(Result,SizeOf(Result),0); FillChar(Result.szoveg,20,' ');

  end;

 

  function TSTDataGrid.NewJelkulcs:TJelkulcsRecord;

  begin

       FillChar(Result,SizeOf(Result),0);

  end;

 

  procedure TSTDataGrid.SavePont(p:TPontRecord);

  var rec_no:longint;

  begin

       If FStellaMapSource<>nil then begin

          If ujrec then FStellaMapSource.UjPont(p)

          else begin

             rec_no:=0;

             While rec_no<FStellaMapSource.cw.vonalszam do

             if VonalVegpontKeres(FStellaMapSource.tm[2],oldPrec.x,oldPrec.y,vrec,rec_no) then

             begin

                  VonalVegpontAtrak(vrec,oldPrec,p);

                  FStellaMapSource.VonalRekordIr(rec_no,vrec);

                  rec_no:=rec_no+1;

                  FStellaMapSource.Vonalrajzol(Canvas,vrec);

             end;

             FStellaMapSource.PontRekordIr(AktPont,p);

          end;

       end else If fStream<>nil then begin

               fStream.Seek(AktPont,0); fStream.Write(p,SizeOf(p));

       end;

  end;

 

  procedure TSTDataGrid.SaveVonal(p:TVonalRecord);

  begin

       If FStellaMapSource<>nil then begin

          If ujrec then FStellaMapSource.UjVonal(p)

          else FStellaMapSource.VonalRekordIr(AktVonal,p);

       end else If fStream<>nil then begin

               fStream.Seek(AktVonal,0); fStream.Write(p,SizeOf(p));

       end;

  end;

 

  procedure TSTDataGrid.SaveFelirat(p:TSzovegRecord);

  begin

       If FStellaMapSource<>nil then begin

          If ujrec then FStellaMapSource.UjFelirat(p)

          else FStellaMapSource.SzovegRekordIr(AktFelirat,p)

       end else If fStream<>nil then begin

               fStream.Seek(AktFelirat,0); fStream.Write(p,SizeOf(p));

       end;

  end;

 

  procedure TSTDataGrid.SaveJelkulcs(p:TJelkulcsRecord);

  begin

       If FStellaMapSource<>nil then begin

          If ujrec then FStellaMapSource.UjJelkulcs(p)

          else FStellaMapSource.JelkulcsRekordIr(AktJelkulcs,p);

       end else If fStream<>nil then begin

               fStream.Seek(AktJelkulcs,0); fStream.Write(p,SizeOf(p));

       end;

  end;

 

  function  TSTDataGrid.FirstPont:TPontRecord;

  begin

      If GetRecSzam(1)>0 then AktPont := 0;

      Result := GetPontRec(AktPont);

  end;

 

  function  TSTDataGrid.NextPont:TPontRecord;

  begin

       If GetRecSzam(1)>AktPont+1 then AktPont := AktPont + 1

       else AktPont := GetRecSzam(1)-1;

       Result := GetPontRec(AktPont);

  end;

 

  function  TSTDataGrid.PriorPont:TPontRecord;

  begin

       If AktPont>0 then AktPont := AktPont - 1

       else AktPont := 0;

       Result := GetPontRec(AktPont);

  end;

 

  function  TSTDataGrid.LastPont:TPontRecord;

  begin

       AktPont := GetRecSzam(1)-1;

       Result := GetPontRec(AktPont);

  end;

 

  function  TSTDataGrid.FirstVonal:TVonalRecord;

  begin

      If GetRecSzam(2)>0 then AktVonal := 0;

      Result := GetVonalRec(AktVonal);

  end;

 

  function  TSTDataGrid.PriorVonal:TVonalRecord;

  begin

       If AktVonal>0 then AktVonal := AktVonal - 1

       else AktVonal := 0;

       Result := GetVonalRec(AktVonal);

  end;

 

  function  TSTDataGrid.NextVonal:TVonalRecord;

  begin

       If GetRecSzam(2)>AktVonal+1 then AktVonal := AktVonal + 1

       else AktVonal := GetRecSzam(2)-1;

       Result := GetVonalRec(AktVonal);

  end;

 

  function  TSTDataGrid.LastVonal:TVonalRecord;

  begin

       AktVonal := GetRecSzam(2)-1;

       Result := GetVonalRec(AktVonal);

  end;

 

  function  TSTDataGrid.FirstFelirat:TSzovegRecord;

  begin

      If GetRecSzam(3)>0 then AktFelirat := 0;

      Result := GetFeliratRec(AktFelirat);

  end;

 

  function  TSTDataGrid.PriorFelirat:TSzovegRecord;

  begin

       If AktFelirat>0 then AktFelirat := AktFelirat - 1

       else AktFelirat := 0;

       Result := GetFeliratRec(AktFelirat);

  end;

 

  function  TSTDataGrid.NextFelirat:TSzovegRecord;

  begin

       If GetRecSzam(3)>AktFelirat+1 then AktFelirat := AktFelirat + 1

       else AktFelirat := GetRecSzam(3)-1;

       Result := GetFeliratRec(AktFelirat);

  end;

 

  function  TSTDataGrid.LastFelirat:TSzovegRecord;

  begin

       AktFelirat := GetRecSzam(3)-1;

       Result := GetFeliratRec(AktFelirat);

  end;

 

  function  TSTDataGrid.FirstJelkulcs:TJelkulcsRecord;

  begin

      If GetRecSzam(4)>0 then AktJelkulcs := 0;

      Result := GetJelkulcsRec(AktJelkulcs);

  end;

 

  function  TSTDataGrid.PriorJelkulcs:TJelkulcsRecord;

  begin

       If AktJelkulcs>0 then AktJelkulcs := AktJelkulcs - 1

       else AktJelkulcs := 0;

       Result := GetJelkulcsRec(AktJelkulcs);

  end;

 

  function  TSTDataGrid.NextJelkulcs:TJelkulcsRecord;

  begin

       If GetRecSzam(4)>AktJelkulcs+1 then AktJelkulcs := AktJelkulcs + 1

       else AktJelkulcs := GetRecSzam(4)-1;

       Result := GetJelkulcsRec(AktJelkulcs);

  end;

 

  function  TSTDataGrid.LastJelkulcs:TJelkulcsRecord;

  begin

       AktJelkulcs := GetRecSzam(4)-1;

       Result := GetJelkulcsRec(AktJelkulcs);

  end;

 

  procedure TSTDataGrid.First;

  begin

   direction := 1;

   Case FRecType of

   rtPont    : FirstPont;

   rtVonal   : FirstVonal;

   rtFelirat : FirstFelirat;

   rtJelkulcs: FirstJelkulcs;

   end;

   valtozott := True;

  end;

 

  procedure TSTDataGrid.Prior;

  begin

   direction := -1;

   Case FRecType of

   rtPont    : PriorPont;

   rtVonal   : PriorVonal;

   rtFelirat : PriorFelirat;

   rtJelkulcs: PriorJelkulcs;

   end;

   valtozott := True;

  end;

 

  procedure TSTDataGrid.Next;

  begin

   direction := 1;

   Case FRecType of

   rtPont    : NextPont;

   rtVonal   : NextVonal;

   rtFelirat : NextFelirat;

   rtJelkulcs: NextJelkulcs;

   end;

   valtozott := True;

  end;

 

  procedure TSTDataGrid.Last;

  begin

   direction := -1;

   Case FRecType of

   rtPont    : LastPont;

   rtVonal   : LastVonal;

   rtFelirat : LastFelirat;

   rtJelkulcs: LastJelkulcs;

   end;

   valtozott := True;

  end;

 

  procedure TSTDataGrid.Save;

  begin

   Case FRecType of

   rtPont    : begin PontRec:=PontKinyeres;SavePont(PontRec);end;

   rtVonal   : begin VonalRec:=VonalKinyeres;SaveVonal(VonalRec); end;

   rtFelirat : begin FeliratRec:=FeliratKinyeres;SaveFelirat(FeliratRec);end;

   rtJelkulcs: begin JelkulcsRec:=JelkulcsKinyeres;SaveJelkulcs(JelkulcsRec);end;

   end;

   If FStellaMapSource<>nil then FStellaMapSource.Refresh;

   ujrec := False;

   valtozott := True;

   invalidate;

  end;

 

  procedure TSTDataGrid.Cancel;

  begin

   Case FRecType of

   rtPont    : begin Pontfeltoltes(PontRec);end;

   rtVonal   : begin Vonalfeltoltes(VonalRec); end;

   rtFelirat : begin Feliratfeltoltes(FeliratRec);end;

   rtJelkulcs: begin Jelkulcsfeltoltes(JelkulcsRec);end;

   end;

   ujrec := False;

  end;

 

  procedure TSTDataGrid.New;

  begin

   Case FRecType of

   rtPont    : Pontrec:=NewPont;

   rtVonal   : VonalRec:=NewVonal;

   rtFelirat : FeliratRec:=NewFelirat;

   rtJelkulcs: JelkulcsRec:=NewJelkulcs;

   end;

   ujrec := True;

  end;

 

  procedure TSTDataGrid.Delete;

  begin

   Case FRecType of

   rtPont    : begin PR:=PontKinyeres;PR.jelzo:=PR.jelzo or 1;SavePont(PR);end;

   rtVonal   : begin VR:=VonalKinyeres;VR.jelzo:=VR.jelzo or 1;SaveVonal(VR); end;

   rtFelirat : begin FR.jelzo:=FR.jelzo or 1;SaveFelirat(FR);end;

   rtJelkulcs: begin JR.jelzo:=JR.jelzo or 1;SaveJelkulcs(JR);end;

   end;

   If FStellaMapSource<>nil then FStellaMapSource.Refresh;

   ujrec := False;

   valtozott := True;

  end;

 

  function TSTDataGrid.IsFilter(var rec):boolean;

  begin

  end;

 

  function  TSTDataGrid.GetPontRec(pos:longint):TPontRecord;

  var vanData : boolean;

  begin

       If FStellaMapSource<>nil then

          Case DataVisibility of

          dgtAll : Result:=FStellaMapSource.PontrekordKap(pos);

          dgtFiltered :

            begin

              VanData := False;

              Repeat

{                dFiltVisible,dFiltActLayer,dFiltDeleted,dFiltSigned}

               VanData := True;

              Until VanData;

            end;

          end

       else If fStream<>nil then begin

               fStream.Seek(pos,0);

               fStream.Read(Result,SizeOf(Result));

            end;

       PontRec := Result;

  end;

 

  function  TSTDataGrid.GetVonalRec(pos:longint):TVonalRecord;

  begin

       If FStellaMapSource<>nil then

          Result:=FStellaMapSource.VonalrekordKap(pos)

       else If fStream<>nil then begin

               fStream.Seek(pos,0); fStream.Read(Result,SizeOf(Result));

            end;

       VonalRec := Result;

  end;

 

  function  TSTDataGrid.GetFeliratRec(pos:longint):TSzovegRecord;

  begin

       If FStellaMapSource<>nil then

          Result:=FStellaMapSource.SzovegrekordKap(pos)

       else If fStream<>nil then begin

               fStream.Seek(pos,0); fStream.Read(Result,SizeOf(Result));

            end;

       FeliratRec := Result;

  end;

 

  function  TSTDataGrid.GetJelkulcsRec(pos:longint):TJelkulcsRecord;

  begin

       If FStellaMapSource<>nil then

          Result:=FStellaMapSource.JelkulcsrekordKap(pos)

       else If fStream<>nil then begin

               fStream.Seek(pos,0); fStream.Read(Result,SizeOf(Result));

            end;

       JelkulcsRec := Result;

  end;

 

  {Megadja a kiszemelt stream méretét: rekordszám}

  function  TSTDataGrid.GetRecSzam(No: longint):longint;

  begin

       If FStellaMapSource<>nil then begin

          Case No of

          1: Result:=FStellaMapSource.cw.Pontszam;

          2: Result:=FStellaMapSource.cw.Vonalszam;

          3: Result:=FStellaMapSource.cw.szovegszam;

          4: Result:=FStellaMapSource.cw.Jelkulcsszam;

          end;

       end else

       If fStream<>nil then begin

          Case No of

          1: Result:=fStream.Size div SizeOf(TPontrecord);

          end;

       end else Result := 0;

  end;

 

procedure TSTDataGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;

    X, Y: Integer);

begin

if not ujrec then GridInit;

inherited MouseDown(Button, Shift, X, Y);

end;

 

procedure TSTDataGrid.KeyPress(var Key: Char);

begin

If CanModify then

Case Key of

#13: begin Save; Key:=#0; end;

#27: Cancel;

end;

inherited KeyPress(Key);

end;

 

procedure TSTDataGrid.GridInit;

begin

RecType:=RecType;

   If (FStellaMapSource<>nil) and (FStellaMapSource.Rajzmod<>rmHelp) then begin

      FStellaMapSource.AlakzatMod:=pKeres;

      Case FRecType of

      rtPont    : FStellaMapSource.Rajzmod:=rmPont;

      rtVonal   : FStellaMapSource.Rajzmod:=rmVonal;

      rtFelirat : FStellaMapSource.Rajzmod:=rmFelirat;

      rtJelkulcs: FStellaMapSource.Rajzmod:=rmJelkulcs;

      end;

   end;

   invalidate;

end;

 

end.