Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DLL's Froms

Posted on 2006-07-03
3
Medium Priority
?
229 Views
Last Modified: 2010-04-05
Hi there!

I created exe file lets say its just myapp.exe. So in this app i have main form with 3 buttons thees buttons on click opens forms. So i like coding dll's in this way i write dll in begining like and then just convert my exe to dll in reality i just replace Application with word Library.

No prob take away some useles things like Application.run and so on. And you have ready dll wich will work.


But what i don't like. When i call a function from dll wich shows form its ok looks fine, but when i call forms from that main form in dll where i had thouse 3 buttons forms popsup like othere application ints not a application, but i can see it on startbar like application. Why it is so can it be made so it would not show the called form from dll like a app. For me its ok :) but if user will see it he won't understand it :)).

so here is a code peace wich i have in dll to call first form its main in dll and its shows it ok :)

library PK;

uses
  ShareMem, //yep :) i use it
  Forms,
  Classes,
  uMainP in 'uMainP.pas' {fProd_Kod},
  uKlases in 'uKlases.pas',
  uProdRekoridi in 'uProdRekoridi.pas',
  AdoToStream in 'AdoToStream.pas',
  uBin in 'uBin.pas' {fBin},
  uProdKriteriji in 'uProdKriteriji.pas' {fProdKriteriji},
  uRezultati in 'uRezultati.pas' {fRezultati},
  uJautajums1 in 'uJautajums1.pas' {fJautajums1},
  uJautajums2 in 'uJautajums2.pas' {fJautajums2},
  uJautajums3 in 'uJautajums3.pas' {fJautajums3},
  u_CardProd in 'u_CardProd.pas' {fCradProd};

{$R *.res}

procedure GoProdCode(_Sesija: pSession; Owner: TComponent); stdcall;
begin

  fProd_Kod := TfProd_Kod.Create(Owner);
  fBin := TfBin.Create(Owner);
  fProdKriteriji := TfProdKriteriji.Create(Owner);
  fRezultati := TfRezultati.Create(Owner);
  fJautajums1 := TfJautajums1.Create(Owner);
  fJautajums2 := TfJautajums2.Create(Owner);
  fJautajums3 := TfJautajums3.Create(Owner);
  fCradProd := TfCradProd.Create(Owner);

  Sesija := _Sesija;

  fProd_Kod.ShowModal;
end;
exports
  GoProdCode;

ok now i'm call GoProdCode from app to see the main form in dll.

i hope you understud what do i meen.

from  fProd_Kod form i will call othere forms wich are in dll and they will popup and will look like othere application they even don't have small icon in upper left corner.

thx,
kristao.

low exp in coding dll's using forms.
0
Comment
Question by:Kristao
3 Comments
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 375 total points
ID: 17033500
probably your Owner parameter is wrong... In most cases when we are using regular forms (not in DLL) the Owner is the Application
0
 
LVL 3

Expert Comment

by:jpedef
ID: 17035098
Hi!

First of all. Maybe you should use FastMM instead of Sharemem. You can get it free from Sourceforge http://fastmm.sourceforge.net

Then you should synchronize application and dll like:

// in dll
var
  dllApp: TApplication;
  fInitialized: boolean;

procedure InitLib(App: TApplication); stdcall;
begin
  // Synchronize application and dll
  if not fInitialized then
  begin
    dllApp := Application;
    Application := App;
    fInitialized := true;
  end;
end;

procedure DLLUnloadProc(Reason: Integer); register;  
begin                                                
  if Reason = DLL_PROCESS_DETACH then  
  begin
    // Dll is about to be unloaded
    Application := DllApp;
    fInitialized := false;
  end;
end;

//... other procedures

exports
  //... other procedures
  InitLib;

begin
  DLLProc := @DLLUnloadProc;
end.

InitLib should be called before any other proc in library.
0
 
LVL 1

Author Comment

by:Kristao
ID: 17035724
Hi there!

Answer is easy m'ky :)

I was on right way when i passed to dll TAplication. But it was't qwait right i needed to pass application.handle. So in reality its integer.

So what this how i did it.

I passed to dll integer wich is handle. and here is code peace:

from app

GoProdCode(ses; Application.Handle);

in dll

procedure GoProdCode(_Sesija: pSession; Owner: Integer); stdcall;
begin
  Application.Handle := Owner;

  Application.CreateForm(TfProd_Kod, fProd_Kod);
  Application.CreateForm(TfBin, fBin);
  Application.CreateForm(TfProdKriteriji, fProdKriteriji);
  Application.CreateForm(TfRezultati, fRezultati);
  Application.CreateForm(TfJautajums1, fJautajums1);
  Application.CreateForm(TfJautajums2, fJautajums2);
  Application.CreateForm(TfJautajums3, fJautajums3);
  Application.CreateForm(TfCradProd, fCradProd);

  Sesija := _Sesija;

  fProd_Kod.ShowModal; //palaižam moduli
end;
exports
  GoProdCode;

=) works fine.

thx.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Screencast - Getting to Know the Pipeline
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question