Napisałem prosty program który łączy się z bazą danych korzystając z komponentów dbExpress. Zainstalowałem na localhost baze MySQL 5.0.27.
Program łaczy się z bazą danych - zdarzenie SQLConnection1AfterConnect jest wykonywane poprawnie. Jednak program wysypuje się przy wywołaniu zdarzenia Button2Click oraz w linii SQLConnection1.GetTableNames(cbTables.Items); w której chce pobrać nazwy tabel z bazy danych i przekazac je do ComboBoxa.
Bład jaki wyrzuca progarm to SQLConnection property required for this operation .
Czy ma to jakiś związek z wersją bazy MySQL, a mianowicie wersją 5.0?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DBXpress, StdCtrls, DB, SqlExpr, FMTBcd, ComCtrls;
type
TForm1 = class(TForm)
SQLConnection1: TSQLConnection;
Button1: TButton;
Label1: TLabel;
lvTable: TListView;
Button2: TButton;
SQLDataSet1: TSQLDataSet;
ProgressBar1: TProgressBar;
cbTables: TComboBox;
procedure Button2Click(Sender: TObject);
procedure SQLConnection1AfterDisconnect(Sender: TObject);
procedure SQLConnection1AfterConnect(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SQLConnection1.Connected := not(SQLConnection1.Connected);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,j: Integer;
ColList: TstringList;
Column: TListColumn;
ListItem: TListItem;
Counter: Integer;
begin
lvTable.Clear;
SQLDataSet1.Active := True;
ColList := TStringList.Create;
try
SQLDataSet1.GetFieldNames(ColList);
Progressbar1.Max := ColList.Count;
for i := 0 to ColList.Count - 1 do
begin
Column := lvTable.Columns.Add;
Column.Caption := ColList.Strings[1];
end;
finally
ColList.Free;
end;
SQLDataSet1.Active := False;
end;
procedure TForm1.SQLConnection1AfterConnect(Sender: TObject);
begin
Label1.Caption := 'Polaczono poprawnie... ';
SQLConnection1.GetTableNames(cbTables.Items); //linia problemowa
end;
procedure TForm1.SQLConnection1AfterDisconnect(Sender: TObject);
begin
Label1.Caption := 'Rozlaczono...';
end;
end.
usupełnienie tagów wątku - furious programming