Einzelnen Beitrag anzeigen

Ykcim

Registriert seit: 29. Dez 2006
Ort: NRW
804 Beiträge
 
Delphi 10.4 Sydney
 
#1

Programm-Aufbau bei asynchronem DB-zugriff

  Alt 26. Nov 2019, 11:27
Hallo Zusammen,
ich versuche gerade meine erste Client/Server Web-Anwendung in Delphi zu erstellen. Ich nutze dazu die Komponenten von TMS (XDATA und WebCore). Aber ich glaube, meine Frage hat nichts mit den Komponenten zu tun…
Ich hoffe, ich kann das Problem und den Aufbau halbwegs verständlich erklären…

Ich ein Form (Form_NMain), dass bei Start der Anwendung erstellt wird.
Im Create wird ein Daten_Form erstellt, dass alle Datenbank-Komponenten enthält (Connection, DataSet, DataSource)

Delphi-Quellcode:
procedure TForm_NMain.WebFormCreate(Sender: TObject);
begin
   if not Assigned(Data_Module) then begin
      Data_Module := TData_Module.Create(Form_NMain);
   end;
end;

procedure TData_Module.WebFormCreate(Sender: TObject);
begin
   if not xConnection.Connected then begin
      if not xConnection_connect then begin
         Showmessage('Es gibt Probleme mit der Verbindung zum DB-Server.');
         Exit;
      end;
   end;
end;

function TData_Module.xConnection_connect: boolean;
   procedure OnConnect;
   begin
      Result:= true;
   end;
   procedure OnError(Error: TXDataWebConnectionError);
   begin
      ShowMessage('XData server connection failed with error: ' +
      Error.ErrorMessage);
      Result:= false;
   end;
begin
   if xConnection.Connected then
      Result:= true
   else
      xConnection.Open(@OnConnect, @OnError);
end;

Im Form_NMain.onShow wird noch eine LogIn-Page erstellt
Delphi-Quellcode:
procedure TForm_NMain.WebFormShow(Sender: TObject);
begin
   Create_frmLogIn;
end;

procedure TForm_NMain.Create_frmLogIn;
begin
   Frame_Control.TabIndex:=0;
   if not Assigned(Form_LogIn) then begin
      Form_LogIn := TForm_LogIn.CreateNew(Sheet_LogIn.ElementID, nil);
   end;
end;
Jetzt sollen die Labels auf der LogIn-Page aus Werten aus der Datenbank bestückt werden.
Delphi-Quellcode:
procedure TForm_LogIn.WebFormCreate(Sender: TObject);
begin
   if Data_Module.xConnection_connect then begin
      Data_Module.Get_Sprache;
      Label_LoginTitel.DataSource:=Data_Module.DSC_Sprache;
      Label_LoginTitel.DataField:='login_Titel';
      Label_LogInUser.DataSource:=Data_Module.DSC_Sprache;
      Label_LogInUser.DataField:='login_lable_username';
      Label_LogInPasswort.DataSource:=Data_Module.DSC_Sprache;
      Label_LogInPasswort.DataField:='login_label_passwort';
   end;
end;
Get_Sprache holt mittels eines Services die Daten aus der Datenbank
Delphi-Quellcode:
procedure TData_Module.Get_Sprache;
   procedure OnResponse(Response: TXDataClientResponse);
   begin
      xDST_Sprache.Close;
      xDST_Sprache.SetJsonData(TJSArray(Response.Result));
      xDST_Sprache.Open;
   end;
begin
   if xConnection_connect then begin
      xClient.RawInvoke('IData_xChangeService.Get_Sprache',[], @OnResponse);
   end;
end;

So der aktuelle Programm-Aufbau und mein Versuch, mit asynchronem Datenbank-Zugriff umzugehen. Vorschläge und Verbesserungen sind sehr willkommen.

Mein Problem ist, dass auf xConnection irgendwie nicht zugegriffen werden kann. Ich bekomme im Chrome den Fehler: Uncaught TypeError: Cannot read property 'GetConnected' of undefined | TypeError: Cannot read property 'GetConnected' of undefined at Object.xConnection_connect (http://localhost:8000/NedCom_Web/NedCom_Web.js:44638:29) at Object.WebFormCreate (http://localhost:8000/NedCom_Web/NedCom_Web.js:95114:37) at Object.cb [as FOnCreate] (http://localhost:8000/NedCom_Web/NedCom_Web.js:222:26) at Object.DoFormLoad (http://localhost:8000/NedCom_Web/NedCom_Web.js:24758:64) at XMLHttpRequest.cb (http://localhost:8000/NedCom_Web/NedCom_Web.js:222:26)
at http://localhost:8000/NedCom_Web/NedCom_Web.js [44638:29]

Kann mir jemand helfen, einen funktionierende Programm-Aufbau für ein asynchrones Programm zu bekomme? Das die Daten vom Server korrekt bereitgestellt ist sichergestellt und definitiv nicht das Problem.

Vielen Dank
Patrick
Patrick

Geändert von Ykcim (26. Nov 2019 um 11:30 Uhr)
  Mit Zitat antworten Zitat