Solved

DLL's Froms

Posted on 2006-07-03
3
217 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 125 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now