Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Forms, Delphi and Darkbasic Pro

Author
Message
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 6th Dec 2004 03:21 Edited at: 6th Dec 2004 03:30
I’m just starting looking into dlls, and was interested in if you could use them to create a form in DBPro. Basically at the moment when creating an application in DBPro I do all the menu screens as a separate executable in Delphi as its much easier being able to use the visual form designer.

What I am interested in is, if you could create a form in a dll using Delphi and then load that dll into a DBPro project and call a function within the code to popup that form. The form would then have to be able to return events, like a button click to DBPro so it could control the outcome like, destroy the form and start the main game, or exit the application.

I was able to find the following code on creating the dll:

And a tutorial about how you would add the form to the dll, but I would be interested in advice on how you would load and execute this through DBPro, and handle events like button clicks, or if this is even possible.

Thanks for any help (and I hope you can make sense of this post)
1tg46
20
Years of Service
User Offline
Joined: 1st Feb 2004
Location: I dont know!
Posted: 6th Dec 2004 06:46
I don't think DBP can handle having a form open that is already premade in a dll, and for that part their are no commands to handle any of the events associated with form. The closest thing that you can use is BlueGUIv2.


Click the sig
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 6th Dec 2004 19:53
Of course it's possible. I'll post a code snippet tonight when I return home.

Play Nice! Play Basic!
Version 1.02 available now!
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 7th Dec 2004 01:34
Thanks that would be really helpful
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Dec 2004 01:35
You could make commands to control the form attributes, but Blue GUI does that for you already.

Isn't it? Wasn't it? Marvellous!
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 7th Dec 2004 01:54
Yes, I could use Blue GUI, but if I could I’d rather work on a solution myself than use a pre-existing DLL. Not that I have anything against Blue, it’s just if I don’t ever try something myself, I’m never going to learn how to do It - and this is an area I find interesting.
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Dec 2004 03:38
There are two ways to do what you intend. We can either create a DLL that will be called with "Load DLL" and "Call DLL" in DBpro or we can create a "Third Party Command".
TPC are a little more complex, so we'll focus on the first method here:
Create a new DLL project in Delphi and add a new Form. For this example we put the following things on the Form
- 1 button named Btn_Exit
- 1 button named Btn_Start
- 1 Edit control named Edt_Name
- 1 Trackbar named Trb_Speed

We have two units now, "Project1" and "Unit1".
In Unit1 we had the following function:

This function will display our function.
Now we assign one procedure to the OnClick event of both buttons (with the Object Inspector). If Btn_Exit is clicked we want to return 1, if Btn_Start is clicked we want to return 2:

Finally we need to be able read the values of the Edit control and the Trackbar:


Before we compile our project, we need to export the functions that shall be accessed from DB:

(see the complete code of Unit1 attached).
Now we save our Project and call it "MyControls". After we compile it there'll be a DLL called "MyControls.DLL" in the project folder.


In DarkBasic. You need to put the DLL in the DBpro Project/App folder.
First we load the DLL:


When we want to popup the form we use

result will be
1 if Btn_Exit was clicked,
2 if Btn_Start was clicked, or
0 if an error occured.

In order to read the text in the edit field we call

and the TrackBar position


That's it.

Play Nice! Play Basic!
Version 1.02 available now!
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 7th Dec 2004 04:03 Edited at: 7th Dec 2004 04:05
Thanks empty, that’s exactly what I had in mind! I'm working through it now and if I have anymore questions I'll post them, but from first looks it seems very clear and complete. Thanks for your help
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Dec 2004 04:05
Quote: " if I have anymore questions I'll post them"

Yes please do so.


Quote: "Thanks for your help "

You're welcome.

Long live Delphi!

Play Nice! Play Basic!
Version 1.02 available now!
1tg46
20
Years of Service
User Offline
Joined: 1st Feb 2004
Location: I dont know!
Posted: 7th Dec 2004 04:24
Is their anyway to do that with Visual Basic .NET 2003?


Click the sig
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 7th Dec 2004 04:46
@empty: Very nice code, the form appeared perfectly, the only problem I'm having is with calling the Edittext and TrackBarPosition function from DBPro, it fails on execution reporting that it could not call the DLL function.



I’m guessing that maybe the form is being removed from memory by "Form1.Release;" and thus so the edit box and track bar. Putting the calls to EditText and TrackBarPosition before PopupForm causes it to crash without error, which I expected as the form hasn’t been created yet. If you could just clear this up I would really appreciate it.

Thanks.
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 7th Dec 2004 17:55 Edited at: 7th Dec 2004 17:56
Yes of course the released form frees the edit and trackbar control too.
For the edit control create a global variable:
var EditText: PChar;
and assign the value of the Edt_Name.Text property in the Edit control's onChange event:

For the trackbar do the same (create a global variable var TrackbarPosition: Integer and assign the Position property in an onChange event to it.)
Then change the functions


Twas late yesterday.

Play Nice! Play Basic!
Version 1.02 available now!
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 7th Dec 2004 20:39
Thanks for the reply, I made the changes and everything’s working fine now. Once again thanks for all your help
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 8th Dec 2004 04:29
Glad I could help.

Play Nice! Play Basic!
Version 1.02 available now!

Login to post a reply

Server time is: 2024-11-21 14:03:42
Your offset time is: 2024-11-21 14:03:42