AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

DLL mit Form

Ein Thema von Capa · begonnen am 27. Feb 2011 · letzter Beitrag vom 5. Mär 2011
 
Capa

Registriert seit: 26. Okt 2003
102 Beiträge
 
RAD-Studio 2010 Arc
 
#2

AW: DLL mit Form

  Alt 27. Feb 2011, 15:55
Nun hab ich doch noch ein Problembei untenstehendem Code
wenn ich die Form1 beende beendet sich das Programm nicht
wirklich ich muss es dann per TaskManager Killen :/



Code der Exe-File:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

procedure CreateForm2(appHandle: THandle); stdcall; external 'DLL1.dllname 'CreateForm2';
procedure ShowForm2; stdcall; external 'DLL1.dllname 'ShowForm2';
procedure HideForm2; stdcall; external 'DLL1.dllname 'HideForm2';
procedure FreeForm2; stdcall; external 'DLL1.dllname 'FreeForm2';
procedure Test(text1,text2,text3: string); stdcall; external 'DLL1.dllname 'Test';


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowForm2;
  Test('Need Help','Capa','DLL Form');
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := False;
  try
    FreeForm2;
  finally
    CanClose := True;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  CreateForm2(Application.Handle);
end;

end.
Code der DLL:
Delphi-Quellcode:
library DLL1;

uses
  SysUtils,
  Classes,
  Forms,
  Sharemem,
  windows,
  DLLUnit1 in 'DLLUnit1.pas{Form2};

{$R *.res}

procedure ShowForm2; stdcall;
begin
  Form2.Show();
end;

procedure HideForm2; stdcall;
begin
  Form2.Hide();
end;

procedure CreateForm2(appHandle: THandle); stdcall;
begin
  if appHandle = 0 then apphandle := GetActiveWindow;
  Application.Handle := appHandle;
  try
    if Form2=nil then
      Form2 := TForm2.Create(Application);
  except
    On E: Exception Do Application.HandleException(E);
  end;
  Application.Handle := 0;
end;

procedure FreeForm2; stdcall;
begin
  FreeAndNil(Form2);
end;

procedure Test(text1,text2,text3: string); stdcall;
begin
  Form2.Listbox1.Items.Add(text1);
  Form2.Listbox1.Items.Add(text2);
  Form2.Listbox1.Items.Add(text3);
end;

exports CreateForm2,
          ShowForm2,
          HideForm2,
          FreeForm2,
               Test;

begin
end.
Code der DLL Form:
Delphi-Quellcode:
unit DLLUnit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    ListBox1: TListBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

end.

Geändert von Capa (27. Feb 2011 um 15:58 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:17 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-2025 by Thomas Breitkreuz