![]() |
DLL Form in Main Programm anzeigen?
^^ Neuer Thread
Also bei der Dll handelt es sich um ein Login Formular. Ich will dass wenn sich mein hauptprogramm öffnet, als erstes die Form der Login.dll sichtbar wir. Wie mache ich die Form einer DLL sichtbar und wie wieder unsichtbar? Und wie kann ich aus einer DLL eine Form meiner Haupt anwendung sichtbar machen? |
Re: DLL Form in Main Programm anzeigen?
Ersteres ist relativ einfach. Du exportierst eine Routine die ungefähr so aussieht:
Delphi-Quellcode:
In umgekehrter Richtung musst du halt dein Form in der DLL hinterlegen. Die ruft dann einfach show und hide auf.
procedure zeigeeinForm;
var f:TMeineDLLFormKlasse; begin f:=TMeineDLLFormKlasse.create(nil); try f.showmodal; //sollte auch mit show gehen finally f.free; end; end; Hoffe geholfen zu haben Apollonius |
Re: DLL Form in Main Programm anzeigen?
Auf jedenfall aber was meinst du damit:
TMeineDLLFormKlasse ?? Klasse?? |
Re: DLL Form in Main Programm anzeigen?
|
Re: DLL Form in Main Programm anzeigen?
Delphi-Quellcode:
:wiejetzt: ?? Verstehe das nicht. Kann mir bitte einer helfen
unit Unit1;
interface uses windows; type TSummenFunktion = function(zahl1, zahl2: integer): integer; stdcall; function addieren(zahl1, zahl2: integer): integer; implementation function addieren(zahl1, zahl2: integer): integer; var SummenFunktion: TSummenFunktion; Handle: THandle; begin Handle:=LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'rechnen.dll')); if Handle <> 0 then begin @SummenFunktion := GetProcAddress(Handle, 'addiere'); if @SummenFunktion <> nil then begin result:=SummenFunktion(zahl1, zahl2); end; FreeLibrary(Handle); end; end; end. |
Re: DLL Form in Main Programm anzeigen?
Das ist garnicht so einfach. In der DLL muss folgendes stehen :
Delphi-Quellcode:
Die ConfigurationMainUnit.pas ist eine ganz einfache Unit mit einem Formular. Dieses kannst Du ganz normal händeln, wie jedes andere Formular auch.
library config;
uses SysUtils, Classes, Windows, Forms, Controls, ExtCtrls, ConfigurationMainUnit in 'ConfigurationMainUnit.pas' {ConfigurationMain}, dll_unit in 'dll_unit.pas'; {$R *.res} procedure configuration(appHandle: THandle); stdcall; begin if appHandle = 0 then apphandle := GetActiveWindow; Application.Handle := appHandle; try with TConfigurationMain.Create(Application) Do try ShowModal finally Free; end except On E: Exception Do Application.HandleException(E); end; Application.Handle := 0; end; exports configuration; begin end. In der DLLunit.pas habe ich dann folgendes stehen :
Delphi-Quellcode:
Und in der MainForm.Unit habe ich dann folgendes stehen um das Formualar aus der ConfigurationMainUnit.pas aufzurufen :
unit dll_unit;
interface procedure configuration(appHandle: THandle); stdcall; implementation procedure configuration(appHandle: THandle); stdcall; external 'config.dll'; end.
Delphi-Quellcode:
So habe ich das gemacht mal für ein Programm. Ich hoffe es hilft dir weiter.
uses
dll_unit; type TConfigWindow = procedure(appHandle: THandle); stdcall; procedure TMainControl.Configuration_btnClick(Sender: TObject); var hDLL : THandle; ConfigWindow : TConfigWindow; begin hDLL := LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'config.dll')); if hDLL <> 0 then begin try ConfigWindow := GetProcAddress(hDLL, 'configuration'); ConfigWindow(Application.Handle); finally FreeLibrary(hDLL); end; end; end; end. |
Re: DLL Form in Main Programm anzeigen?
was ist das: ConfigurationMainUnit.pas? Edit: Ok habs gecheckt
Delphi-Quellcode:
[Fehler] Loginpr.dpr(31): E2003 Undefinierter Bezeichner: 'TConfigurationMain'
try
with TConfigurationMain.Create(Application) Do try [Fehler] Loginpr.dpr(31): E2029 'DO' erwartet, aber Bezeichner 'Create' gefunden [Fehler] Loginpr.dpr(33): E2003 Undefinierter Bezeichner: 'ShowModal' [Fehler] Loginpr.dpr(35): E2003 Undefinierter Bezeichner: 'Free' |
Re: DLL Form in Main Programm anzeigen?
TConfigurationMain musst Du natürlich an Dein Formular anpassen. Für die Fehler fehlen Dir entweder noch Units oder Du hast noch einen anderen Fehler drin. Zeige uns doch mal Deinen Sourcecode.
|
Re: DLL Form in Main Programm anzeigen?
Delphi-Quellcode:
library Loginpr;
uses SysUtils, Classes, Windows, Forms, Controls, ExtCtrls, ConfigurationMainUnit in 'ConfigurationMainUnit.pas' {ConfigurationMain}, Login in 'Login.pas'; {$R *.res} procedure configuration(appHandle: THandle); stdcall; begin if appHandle = 0 then apphandle := GetActiveWindow; Application.Handle := appHandle; try with TConfigurationMain.Create(Application) Do try ShowModal finally Free; end except On E: Exception Do Application.HandleException(E); end; Application.Handle := 0; end; exports Configuration; begin end. |
Re: DLL Form in Main Programm anzeigen?
Du musst die Procedure Configuration anpassen. Ich habe Dir lediglich nur ein Beispiel für ein anderes Formualr geliefert.
So könnte Deine Login.dpr aussehen :
Delphi-Quellcode:
Nochmal, so könnte Deine Login.dpr aussehen. Es kommt darauf an, welchen Namen Du dem Formular gegeben hast.
library Loginpr;
uses SysUtils, Classes, Windows, Forms, Controls, ExtCtrls, Login in 'Login.pas'; {$R *.res} procedure LoginWindow(appHandle: THandle); stdcall; begin if appHandle = 0 then apphandle := GetActiveWindow; Application.Handle := appHandle; try with TLoginMain.Create(Application) Do try ShowModal finally Free; end except On E: Exception Do Application.HandleException(E); end; Application.Handle := 0; end; exports LoginWindow; begin end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:48 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz