Hey Leute!
Ich bin relativer Neuling im Delphi Bereich. Meine Erfahrungen beschränken sich auf die einfachsten Spielereien im Informatikunterricht.
Mit MySQL kenne ich mich aber generell gut aus.
Da ich nun eine Facharbeit über ein kleines Datenbankprojekt schreiben muss, wäre es sehr gelegen, wenn mir jemand ein wenig tMySQL erläutern könnte.
Ich habe zur Zeit immer das Problem, dass ich keinen Owner angeben kann, da das Form1 in Unit1 liegt und ich die Datenbankaktionen ausgelagert habe in uDaten.
Bin für jeden Tipp dankbar!
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51:
| unit uDaten;
interface uses Dialogs, mySQLClient, sysUtils, mySQLCommon;
const cHOST = 'localhost'; cUSER = 'root'; cPASS = '';
type tDaten = class ( TObject )
private hMySQL : TmySQLClient; protected procedure mysql_connect(pHost, pUser, pPass : string); virtual; procedure mysql_close; virtual;
public constructor create; virtual; destructor destroy; virtual;
implementation
constructor tDaten.create; begin hMySQL := TMySQLClient.Create(Form1); self.mysql_connect(cHOST, cUSER, cPASS); end;
destructor tDaten.destroy; begin self.mysql_close; end;
procedure tDaten.mysql_connect(pHost, pUser, pPass : string); begin hMySQL.Username := pUser; hMySQL.Hostname := pHost; hMySQL.Password := pPass; hMySQL.Connect; end;
procedure tDaten.mysql_close; begin hMySQL.Close; end;
end. |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
| unit Unit1; interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ToolWin, ComCtrls, Unit2, Unit3, StdCtrls, DB, DBTables, uDaten, mySQLClient, mySQLCommon; {$I mysqlinc.inc} type TForm1 = class(TForm) procedure btCloseClick(Sender: TObject); procedure FormCreate(Sender: TObject); private
public hDaten : tDaten;
end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btCloseClick(Sender: TObject); begin
hDaten.destroy; Close; end;
procedure TForm1.FormCreate(Sender: TObject); begin hDaten := tDaten.create; end;
end. |