Autor Beitrag
kežman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

WIN XP HE
D6 Prof
BeitragVerfasst: So 30.01.05 13:59 
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!
ausblenden volle Höhe Delphi-Quelltext
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);       // Hier liegt der Fehler
  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.
ausblenden volle Höhe Delphi-Quelltext
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;        // Formbasis

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.
Robert.Wachtel
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 895
Erhaltene Danke: 7

Windows 7 Ultimate x64
D5 Ent, D7 Arch, RAD Studio 2010 Pro, VS 2008
BeitragVerfasst: So 30.01.05 15:09 
kežman hat folgendes geschrieben:
[...] 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.[...]

Na, dann verzichte doch auf den Owner und kümmere Dich selbst um die Freigabe des Objekts:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
constructor tDaten.create;
 begin
  hMySQL := TMySQLClient.Create(nil);
  self.mysql_connect(cHOST, cUSER, cPASS);
 end;

destructor tDaten.destroy;
 begin
  self.mysql_close;
  hMySQL.Free;
 end;
kežman Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30

WIN XP HE
D6 Prof
BeitragVerfasst: So 30.01.05 15:13 
Danke.

Wusste nicht, dass ich nil auch als Owner etc angeben kann.