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:
Function PopupForm: Integer; stdcall
begin
result := 0;
Form1 := TForm1.Create(Application);
try
result := Form1.ShowModal;
finally
Form1.Release;
end;
end;
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:
procedure TForm1.Btn_Exit(Sender: TObject);
begin
if Sender = Btn_Exit then ModalResult := 1 else ModalResult := 2;
end;
Finally we need to be able read the values of the Edit control and the Trackbar:
Function EditText: PChar; stdcall;
begin
result := PChar(Form1.Edt_Name.Text);
end;
Function TrackbarPosition: Integer; stdcall;
begin
result := Form1.Trb_Speed.Position;
end;
Before we compile our project, we need to export the functions that shall be accessed from DB:
exports
PopupForm,
EditText,
TrackBarPosition;
(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:
Load DLL "MyControls.DLL", 1
When we want to popup the form we use
result = Call DLL(1,"PopupForm")
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
EditText$ = Call DLL(1,"EditText")
and the TrackBar position
TrackBarPos = Call DLL(1, "TrackBarPosition")
That's it.
Play Nice!
Play Basic!
Version 1.02 available now!