Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using Forms in a Delphi DLL

Posted on 2004-04-14
4
Medium Priority
?
394 Views
Last Modified: 2010-04-05
Hello, I am a complete newbie to Delphi and have been trying to create a AIM Plugin.

Below is what i am using to Load my DLL when AIM starts:

library AIMPlugin;

uses
  SysUtils,
  Windows,
  Messages,
  Classes,
  Unit1 in 'Unit1.pas' {Form1};

{$E .ocm}

//Called when AIM Starts
function OCMOpen(dword:DWORD):Boolean;stdcall;
begin
Form1.Show;
end;

//Called when AIM Closes
function OCMClose():Boolean;stdcall;
begin
Exit;
end;

//Called when an even occurs
function OCMRegister(int1, int2 ,int3, int4 : Integer):Integer;stdcall;
begin

end;

exports OCMOpen, OCMClose, OCMRegister;

end.

Now this works, but when trying to show a Form, i get nasty errors, Access Violations and a Runtime 217 error. I have played around and modified things, only to find it made things worse. Is there something im doing wrong?? I can show messgaboxes and stuff, but not show Forms. If i replace the Form1.Show; with a messagebox, it shows when AIM loads and no errors. Should i be using ShareMem? Please help somone, any info would be greatly appreciated!
0
Comment
Question by:EvilPhil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Expert Comment

by:BJThomsen
ID: 10828491
I see you are doing a Form1.show but I see no code where you actually create the form.
0
 
LVL 3

Accepted Solution

by:
BJThomsen earned 500 total points
ID: 10828500
You need to so a Form1 := TForm1.Create(nil);
before the show.

Not sure but probably a Form1.Free; in the function OCMClose.
0
 

Author Comment

by:EvilPhil
ID: 10828710
O wow! Thanx man!!!! WOw i feel STUPID!!! I changed some stuff into this:

{$E .ocm}
{$R *.dfm}

type
  TForm1 = class(TForm)
    Button1: TButton;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

function OCMOpen(dword:DWORD):Boolean;stdcall;
begin

   Form1 := TForm1.Create(nil);
   Form1.Show;

end;

And now it works!!! This is great! Thanx alot!!! I though i could call my form from inside Unit1.pas, but now im starting to understand how Delphi works, thanx alot!!! I need to go read some books...
0
 

Expert Comment

by:loadman
ID: 20634503
Great!
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 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