Solved

DLL's Froms

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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