Thema: Delphi StringGrid vergleichen!

Einzelnen Beitrag anzeigen

thiagojonas

Registriert seit: 31. Aug 2008
Ort: Wolfenbüttel
338 Beiträge
 
#33

Re: StringGrid vergleichen!

  Alt 25. Sep 2008, 19:20
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    air_dg: TStringGrid;
    fligths_dg: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    flugnummer: integer;
    function getFlugNummer: string;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.getFlugNummer: string;
begin
    result := format('%3.3d',[flugnummer + 1]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var Txt2Find : String;
    Index : Integer;

function GetGrid2Index(Grid:TStringGrid;Txt2Find:String):Integer;
var i : Integer;
begin
  Result:=-1;
with Grid do
      for i:=FixedRows to RowCount-1 do
        if (fligths_dg.Cells[1,i]= Txt2Find) then begin
          Result:=i;
          Break;
          end;
  end;

begin
  Txt2Find:=air_dg.Cells[1,air_dg.Row];
  Index :=GetGrid2Index(fligths_dg,Txt2Find);
  if Index>-1 then fligths_dg.Cells[5,Index] := FormatDateTime('hh:mm',now);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if air_dg.Cells[air_dg.FixedCols,Pred(air_dg.RowCount)] <> 'then
    air_dg.RowCount := Succ(air_dg.RowCount);
    air_dg.Cells[air_dg.FixedCols,Pred(air_dg.RowCount)] := getFlugNummer;
    air_dg.Cells[1,Pred(air_dg.RowCount)] := 'Hallo';
    air_dg.Cells[2,Pred(air_dg.RowCount)] := 'Rainer';
    air_dg.Cells[3,Pred(air_dg.RowCount)] := 'Horst';

 if fligths_dg.Cells[fligths_dg.FixedCols,Pred(fligths_dg.RowCount)] <> 'then
    fligths_dg.RowCount := Succ(fligths_dg.RowCount);
    fligths_dg.Cells[fligths_dg.FixedCols,Pred(fligths_dg.RowCount)] := getFlugNummer;
    fligths_dg.Cells[1,Pred(fligths_dg.RowCount)] := 'Hallo';
    fligths_dg.Cells[2,Pred(fligths_dg.RowCount)] := 'Rainer';
    fligths_dg.Cells[3,Pred(fligths_dg.RowCount)] := 'Horst';
    fligths_dg.Cells[4,Pred(fligths_dg.RowCount)] := FormatDateTime('hh:mm',now);
    fligths_dg.Cells[6,Pred(fligths_dg.RowCount)] := '';
    
  inc(flugnummer);
end;

end.
Meinst Du den?
  Mit Zitat antworten Zitat