Solved

DLL's Froms

Posted on 2006-07-03
3
218 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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

21 Experts available now in Live!

Get 1:1 Help Now