home *** CD-ROM | disk | FTP | other *** search
- unit G_main;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- QDB, QDBView, Menus, StdCtrls, Grids;
-
- type
- TG_form = class(TForm)
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Open1: TMenuItem;
- Close1: TMenuItem;
- N1: TMenuItem;
- Exit1: TMenuItem;
- OpenDialog: TOpenDialog;
- QI: TQDBItem;
- Grid: TStringGrid;
- procedure Open1Click(Sender: TObject);
- procedure Close1Click(Sender: TObject);
- procedure Exit1Click(Sender: TObject);
- procedure QIWarnNoData(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure DisplayRow(r: integer);
- end;
-
- var
- G_form: TG_form;
-
- implementation
-
- uses
- TypInfo;
-
- {$R *.DFM}
-
- const
- colofs = 2; // first two columns are reserved
- rowofs = 2; // first two rows are reserved
-
- procedure TG_form.DisplayRow(r: integer);
- var
- n: integer;
- begin
- // row number in first cell
- Grid.Cells[0,r]:=IntToStr(r-rowofs);
- // key in the next
- Grid.Cells[1,r]:=QI.Key;
- // and then the field values as strings
- for n:=0 to Grid.ColCount-1-colofs do
- Grid.Cells[n+colofs,r]:=QI.AsString[n];
- end;
-
- procedure TG_form.Open1Click(Sender: TObject);
- var
- n: integer;
- r: integer;
- begin
- with OpenDialog do
- begin
- if Execute then
- begin
- try
- // if it isn't a QDB file we have an exception to handle
- QI.FileName:=FileName;
- // load the field info
- QI.FetchStructure;
- // a column for every field plus two extra
- Grid.ColCount:=QI.FieldCount+colofs;
- // a row for every item plus two extra
- if QI.Count > 0 then
- Grid.RowCount:=rowofs+QI.Count
- else
- begin
- // except for an empty file ...
- // we need to show an extra empty row
- Grid.RowCount:=rowofs+1;
- for n:=0 to Grid.ColCount-1 do
- Grid.Cells[n,rowofs]:='';
- end;
- // left column is fixed
- Grid.FixedCols:=1;
- // top two rows are fixed
- Grid.FixedRows:=2;
- // fill in the first two column headings
- Grid.Cells[0,0]:='Field Name';
- Grid.Cells[0,1]:='Field Type';
- Grid.Cells[1,0]:='Key';
- Grid.Cells[1,1]:='';
- // then add the rest
- for n:=0 to Grid.ColCount-colofs do
- begin
- // the field name on top
- Grid.Cells[n+colofs,0]:=QI.FieldNames[n];
- // and the kind of field beneath
- Grid.Cells[n+colofs,1]:=GetEnumName(TypeInfo(TQDBFieldType),ord(QI.FieldTypes[n]));
- end;
- // then if the file isn't empty
- if QI.Count > 0 then
- begin
- r:=rowofs;
- // go to the start of the file ...
- // and display each item as a separate row
- QI.FirstItem;
- repeat
- DisplayRow(r);
- inc(r);
- QI.NextItem;
- until QI.EoF;
- // we hit end of file before we have displayed
- // the last item so we do it now
- DisplayRow(r);
- end;
- except
- // handle the exception if the file isn't QDB
- on EQDBFileError do
- begin
- ShowMessage(Filename + ' is not a valid QDB file');
- QI.Filename:='';
- end;
- else
- raise;
- end;
- end;
- end;
- end;
-
- procedure TG_form.Close1Click(Sender: TObject);
- begin
- QI.Filename:='';
- end;
-
- procedure TG_form.Exit1Click(Sender: TObject);
- begin
- QI.FileName:='' ;;
- Close;
- end;
-
- procedure TG_form.QIWarnNoData(Sender: TObject);
- begin
- // a dummy handler to stop the exception when we
- // operate on an empty file
- end;
-
- end.
-