nit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, Data.DB, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error,
FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
FireDAC.Phys.PG, FireDAC.Phys.PGDef, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
FireDAC.DApt, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
Vcl.ExtCtrls,
Vcl.DBCtrls,
Vcl.Grids,
Vcl.DBGrids,
FireDAC.Comp.UI,
Vcl.StdCtrls,
Vcl.Mask;
type
TForm1 =
class(TForm)
DataSource1: TDataSource;
FDQuery1: TFDQuery;
FDPhysPgDriverLink1: TFDPhysPgDriverLink;
FDConnection1: TFDConnection;
Button1: TButton;
Memo1: TMemo;
StringGrid1: TStringGrid;
Label1: TLabel;
RadioGroup1: TRadioGroup;
procedure Button1Click(Sender: TObject);
private
function GetWidthText(
const Text:
String; Font:TFont) : Integer;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,Zähler,OldW,NewW: Integer;
begin
OldW:= 64;
for i := 0
to StringGrid1.RowCount
do
StringGrid1.Rows[i].Clear;
StringGrid1.RowCount:= 0;
StringGrid1.ColCount:= 0;
Zähler:= 1;
if FDQuery1.Active
then FDQuery1.Close;
FDQuery1.SQL.Text:= Memo1.Text;
FDQuery1.Open;
StringGrid1.ColCount:= FDQuery1.Fields.Count;
for i := 0
to FDQuery1.Fields.Count - 1
do begin
StringGrid1.Cells[i, 0]:= FDQuery1.Fields[i].FieldName;
{List[i];}
end;
while not FDQuery1.Eof
do begin
StringGrid1.RowCount:= StringGrid1.RowCount +1;
for i := 0
to FDQuery1.Fields.Count - 1
do begin
StringGrid1.Cells[i, Zähler] := FDQuery1.Fields[i].AsString;
end;
Inc(Zähler);
FDQuery1.Next;
end;
Zähler:= 0;
i:= 0;
while i <= StringGrid1.ColCount
do begin
while Zähler <= StringGrid1.RowCount
do begin
NewW:=GetWidthText(StringGrid1.Cells[i, Zähler], StringGrid1.Font);
if NewW > OldW
then begin
OldW:= NewW;
end;
Inc(Zähler);
end;
Zähler:= 0;
if OldW > 64
then Stringgrid1.ColWidths[i] := OldW+10;
OldW:= 64;
Inc(i)
end;
StringGrid1.Refresh;
end;
function TForm1.GetWidthText(
const Text:
String; Font:TFont) : Integer;
var LBmp: TBitmap;
begin
LBmp := TBitmap.Create;
try
LBmp.Canvas.Font := Font;
Result := LBmp.Canvas.TextWidth(Text);
finally
LBmp.Free;
end;
end;
end.