Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi DLL Form in Main Programm anzeigen? (https://www.delphipraxis.net/92714-dll-form-main-programm-anzeigen.html)

napsterxx 24. Mai 2007 21:28


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?

Apollonius 24. Mai 2007 21:53

Re: DLL Form in Main Programm anzeigen?
 
Ersteres ist relativ einfach. Du exportierst eine Routine die ungefähr so aussieht:
Delphi-Quellcode:
procedure zeigeeinForm;
var f:TMeineDLLFormKlasse;
begin
f:=TMeineDLLFormKlasse.create(nil);
try
  f.showmodal; //sollte auch mit show gehen
finally
  f.free;
end;
end;
In umgekehrter Richtung musst du halt dein Form in der DLL hinterlegen. Die ruft dann einfach show und hide auf.
Hoffe geholfen zu haben
Apollonius

napsterxx 24. Mai 2007 22:01

Re: DLL Form in Main Programm anzeigen?
 
Auf jedenfall aber was meinst du damit:

TMeineDLLFormKlasse


?? Klasse??

inherited 24. Mai 2007 22:04

Re: DLL Form in Main Programm anzeigen?
 
www.dsdt.info ->Tutorials->Delphi-Language(oder so)->DLLs
Dynamisches einbinden von DLLs

napsterxx 24. Mai 2007 22:08

Re: DLL Form in Main Programm anzeigen?
 
Delphi-Quellcode:
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.
:wiejetzt: ?? Verstehe das nicht. Kann mir bitte einer helfen

RWarnecke 24. Mai 2007 22:09

Re: DLL Form in Main Programm anzeigen?
 
Das ist garnicht so einfach. In der DLL muss folgendes stehen :
Delphi-Quellcode:
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.
Die ConfigurationMainUnit.pas ist eine ganz einfache Unit mit einem Formular. Dieses kannst Du ganz normal händeln, wie jedes andere Formular auch.
In der DLLunit.pas habe ich dann folgendes stehen :
Delphi-Quellcode:
unit dll_unit;

interface
procedure configuration(appHandle: THandle); stdcall;

implementation

procedure configuration(appHandle: THandle); stdcall; external 'config.dll';

end.
Und in der MainForm.Unit habe ich dann folgendes stehen um das Formualar aus der ConfigurationMainUnit.pas aufzurufen :
Delphi-Quellcode:
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.
So habe ich das gemacht mal für ein Programm. Ich hoffe es hilft dir weiter.

napsterxx 24. Mai 2007 22:19

Re: DLL Form in Main Programm anzeigen?
 
was ist das: ConfigurationMainUnit.pas? Edit: Ok habs gecheckt
Delphi-Quellcode:
try
with TConfigurationMain.Create(Application) Do
try
[Fehler] Loginpr.dpr(31): E2003 Undefinierter Bezeichner: 'TConfigurationMain'
[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'

RWarnecke 24. Mai 2007 22:28

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.

napsterxx 24. Mai 2007 22:33

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.

RWarnecke 24. Mai 2007 22:36

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:
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.
Nochmal, so könnte Deine Login.dpr aussehen. Es kommt darauf an, welchen Namen Du dem Formular gegeben hast.


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:48 Uhr.
Seite 1 von 2  1 2      

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