Jeg har, siden det blev kendt at ADO-tabeller med rette værktøj - som kan fås på nettet kan åbnes af udenforstående (arbejder med lægedata - derfor ) IKKE brugt ADO-tabeller overhovedet, men andre typer databaser.
Denne koden KAN MÅSKE bruges. Men prøv selv.
Den kan (hos mig) hente FIELDNAMES og data (men ikke datatyperne - VarChar, Integer etc)
KRistian
procedure TForm1.Button1Click(Sender: TObject); VAR MName : String; N, n1 : Integer; MyDef : Variant;
begin MyTable.GetFieldNames(Listbox1.Items); With DBgrid1.DataSource.DataSet Do BEGIN First; For N := 0 to RecordCount -1 DO BEGIN For N1 := 0 to FieldCount -1 DO Listbox2.Items.Add(VARtoStr(Fields[N1].AsVariant)); NExt; END; END; end;
private tablename, fieldname : string; refr : boolean; { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListBox1Click(Sender: TObject); begin with listbox1 do tablename := items[itemindex]; with listbox1 do db.GetFieldNames(tablename, listbox2.Items);
end; var ptr : integer;
procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (shift = [ssctrl]) and (key = vk_return) then begin btngo.click; end; end;
procedure TForm1.Button1Click(Sender: TObject); var s : string; str : tstringlist; i : integer; begin str := tstringlist.Create; with query1 do begin try disablecontrols; first; s := ''; for i := 0 to fieldcount-1 do s := s +fields[i].displaylabel+chr(vk_tab); str.add(s); while not eof do begin s := ''; for i := 0 to fieldcount-1 do s := s +fields[i].asstring+chr(vk_tab); str.add(s); next; end; finally enablecontrols; end; clipboard.astext := str.text; caption := 'OK'; end; end;
var memory : tstringlist;
function extract(s : string) : string; var p : integer; str : tstringlist; begin str := tstringlist.Create; repeat p := pos ('\', s); if p > 0 then str.add(copy(s,1,p-1)); s := copy(s,p+1, 1000); until p = 0; str.add(s); result := str.Text; end;
function pack(str : tstrings) : string; var s, sl : string; i : integer; begin s := ''; sl := ''; for i := 0 to str.count-1 do begin if str[i] <> '' then s := s +sl+str[i]; if i=0 then sl := '\'; end; result := s; end;
procedure TForm1.FormCreate(Sender: TObject); begin db.GetTableNames(listbox1.Items); if sender = nil then exit; memory := tstringlist.Create; try memory.loadfromfile('sql.his'); except
procedure TForm1.FormDestroy(Sender: TObject); begin try memory.savetofile('sql.his'); except
end;
end;
procedure TForm1.btnGoClick(Sender: TObject); var s : string; i : integer; begin query1.close; query1.sql.text := memo1.Lines.Text; try if pos('select', query1.SQL.Text) = 1 then query1.open else begin query1.ExecSQL; if refr then begin with listbox1 do db.GetFieldNames(tablename, listbox2.Items);
formCreate(nil); refr := false; end; end; finally s := pack(memo1.lines); repeat i := memory.indexof(s); if i > -1 then memory.delete(i); until i = -1; memory.Insert(0, s); end; ptr := 0; Updatebtns; end;
procedure TForm1.bnextClick(Sender: TObject); begin dec(ptr); memo1.lines.Text := extract(memory[ptr]);
updatebtns; end;
procedure TForm1.bpriorClick(Sender: TObject); begin inc(ptr); memo1.lines.Text := extract(memory[ptr]);
procedure TForm1.ListBox2Click(Sender: TObject); begin
with listBox2 do if itemindex <> -1 then fieldname := items[itemindex]; memo1.lines.text := 'select '+fieldname+' from '+tablename; btngo.click; end;
procedure TForm1.AddFieClick(Sender: TObject); var ft : string; begin case (sender as tmenuitem).tag of 0 : ft := 'integer'; 1 : ft := 'varchar(00)'; 2 : ft := 'date'; end;
function max(a,b : real) : real; begin if a > b then result := a else result := b; end;
procedure TForm1.Button2Click(Sender: TObject); var maxlen : array [0..40] of real; i : integer; function pad(s : string; len : integer ): string; begin while length(s) < len do s := s + ' '; result := copy(s,1,len); end;
begin with query1 do begin fillchar(maxlen, sizeof(maxlen), #0); first; while not eof do begin for i := 0 to fieldcount-1 do maxlen[i] := max(length(fields[i].asstring), maxlen[i]); next; end; assignfile(output, 'c:\test.txt'); rewrite(output); first; while not eof do begin for i := 0 to fieldcount-1 do write(pad(fields[i].asstring,round(maxlen[i]+1))); writeln; next; end; closefile(output); end;
end;
procedure TForm1.DBGrid1ColEnter(Sender: TObject); begin with dbgrid1 do case columns[selectedindex].field.datatype of ftInteger : caption := 'integer'; ftautoinc : caption := 'integer, identity'; ftfloat : caption := 'Float'; ftString : begin caption := 'String '+inttostr(columns[selectedindex].field.size); end; ftDatetime : begin caption := 'Dato'; end; else caption := '??'; end; end;
Arne_V og Snestrup2000 - smid et svar - jeg deler point mellem jer alle 3... (dvs. inkl "Kloge")...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.