Jump to content
Sign in to follow this  
rhumbaflappy

Delphi and SimConnect

Recommended Posts

Hi all.I have a conversion of the SimConnect.h file that seems to work with Delphi.I've used it with Delphi7 and the new win32 Turbo Delphi Explorer ( FREE ):http://www.turboexplorer.com/mirror(Note: you cannot have both Turbo Delphi Explorer and Turbo C++ Explorer installed at the same time... use one or the other.)A test file that includes all the needed support files here:http://webpages.charter.net/ludowr/DelphiOpenClose.zipIncluded in the zip is a MANIFEST file, a RES file and an RC file, along with SimConnect_4.pas ( the H file conversion ).The above four files must be in the project's base folder so the compiler can find them. OpenClose.dpr is the actual program. The code is pretty simple.The compiled OpenClose.exe is a native win32 file that will find the SimConnect.dll on your computer... so it is truly "stand-alone". No further playing around with the manifest file, etc... :) It needs no runtime libraries, no .NET, and can be placed anywhere on your computer.What OpenClose.exe does is simply open a connection to FSX via SimConnect, and then close it. It's a command-line program, so run it from a command window ( CMD.exe ).SimConnect_4.pas is my 4th attempt to get this thing working... I'm sure it has errors, but we have a start. If anyone else can improve it, feel free to post it here ( or at Arno's website ) for testing! Hopefully within a month or two, we'll have a solid version. So, we now have SimConnect working in the Delphi environment... lots of fun for RAD Windows form developers, and programmers that like Delphi.( Jacky! Please test this with Delphi 6... it should work, and hopefully will get you started. )Dick

Share this post


Link to post
Share on other sites

Hi Jacky.This example ( SimConnect_4.pas ) has only a few functions implemented! There are actually 68 functions in the DLL to call. So we have 65 more to go... and the syntax may be wrong in what I have.Make a list of what you need for calls, and we'll see if we can add them."What should I give as fEpsilon and DatumID ?"The SDK indicates 0 would work.Dick

Share this post


Link to post
Share on other sites

Hi Jacky.YES!!! Anything you can do to improve the use of SimConnect using Delphi is most welcome.Truthfully, I've become much more comfortable with C#. But it seems a shame that Delphi would be left in the cold. And this thread could be a good place to exchange improvements and additions to the eventual ( and final ) SimConnect.pas file. :)Dick

Share this post


Link to post
Share on other sites
Guest JuiceRabbit

This is good news... thanks for your efforts! :-beerchug

Share this post


Link to post
Share on other sites
Guest scotthendry

Dick:Thank you so much for providing us Delphi programmers a way into SimConnect. I downloaded openclose5 and had a look at it. I sort of understand it. I haven't got my copy of FSX yet, so that may clear things up more when I look at that. In the mean time, is there any chance of you updating the openclose program in line with Brian G's tutorials? That would help my understanding along heaps!Thanks againScott

Share this post


Link to post
Share on other sites

Hi Scott.Jacky ( JAB ) has pretty much taken over the SimConnect.pas development. He is improving the "include" file, and is experimenting with it. My involvement is mostly from curiosity as to if it would work... and it appears it does. By NO means am I a good Delphi programmer.I actually program with C# ( when I'm forced into it ). It just seemed a shame that Delphi was left out of the SimConnect development loop, as several programers prefer it.Dick

Share this post


Link to post
Share on other sites
Guest Jacky Brouze

Hello,Yes, I am working on Dick's SimConnect.pas (actually version 6).At the moment, my test program is able to Open / Close, Load Flight / SaveFlight, Get one aircraft information ... I have problem to makeSimConnect accept a second "AddToDataDefinitions" (???) but I am surethat I will get the trick ... Do not hesitate to contact me if you are interested ...A+Jacky

Share this post


Link to post
Share on other sites
Guest scotthendry

Jacky:Good on ya for taking your time to provide a Delphi interface to FSX. I have done some Delphi programming (mostly database stuff), but not so much windows API stuff. However If you need some help please don't hesitate to ask for assistance.

Share this post


Link to post
Share on other sites
Guest Jacky Brouze

Hi Scott,Some progress : I can now get several data from SimConnect in one shot using SimConnect_GetNextDispatch.I would like now the get data using a callback (defined by SimConnect_CallDispatch.Here is the actual declare : Function SimConnect_CallDispatch( hSimConnect: THandle; pfcnDispatch: TDispatchProc; pContext: Pointer ) : LongInt; StdCall;which is the Delphi translation for HRESULT SimConnect_CallDispatch( HANDLE hSimConnect, DispatchProc pfcnDispatch, void * pContext );but I am unable to buid this "TDispatchProc".Here is how it looks in C: void CALLBACK DispatchProc( SIMCONNECT_RECV* pData, DWORD cbData void * pContext );All the test I have made result in a crash as soon as this DispatchProc is called ... Can you help me ? Send me a nail if you want the Delphi sources.A+Jacky

Share this post


Link to post
Share on other sites
Guest KenAdam

All,Having got a copy of the latest version of SimConnect.pas from Jacky, and made some changes, I've now got it working both using polled transfers (looping on SimConnect_CallDispatch) and using Message driven events.I used the "Tagged Data" example from the SDK and have a version of this running in a Delphi Windows application.I plan to convert more for the demos soon, hopefully post the code on a convenient website.Ken

Share this post


Link to post
Share on other sites
Guest Jacky Brouze

Hi Dick,I just go it working without loops !!!Preview : In the MainForm declaration : > Procedure SimConnectEvent (Var Msg:TMessage); Message WM_User;SimConnect opening :> If SimConnect_Open(hSimConnect,'Test',Handle,WM_USER,0,0)<>S_Ok Then ...The procedure :> Procedure TfMain.SimConnectEvent;> Begin> ...> Here I call SimConnect_GetNextDispatch and process it > ...> End;A+Jacky

Share this post


Link to post
Share on other sites
Guest KenAdam

I've uploaded a zip of where I am so far (I'm now using this to write the interface program I really needed to talk to a real avionics display).This version allows you to either use the busy-wait polling method or the windows event approach (I kept the busy wait to show what the SDK example does - of course a real app will want to use the windows message).I plan to convert more examples.Feedback welcome!Ken.http://forums.avsim.net/user_files/165010.zip

Share this post


Link to post
Share on other sites
Guest scotthendry

Ken:Had a look at your files (briefely). Some thoughts are as followsFirstly, thank you for sharing your work with the rest of us. I for one need all the ideas (help) I can get!Secondly, you probably haven't got that far yet but some of the data types are wrong. the following are classed as follows // SIMCONNECT_DATAType_WAYPOINT SIMCONNECT_DATA_WAYPOINT = record Latitude: double; Longitude: double; Altitude: double; Flags: LongInt; ktsSpeed: double; percentThrottle: double; end; // SIMCONNECT_DATA_LATLONALT SIMCONNECT_DATA_LATLONALT = record Latitude: double; Longitude: double; Altitude: double; end; // SIMCONNECT_DATA_XYZ SIMCONNECT_DATA_XYZ = record x: double; y: double; z: double; end;in the SIMCONNECT.h they are classed as float which is a 4 byte value whereas Doubles are 8 bytes. (Update,I'm wrong here, they ARE doubles in the original Oooooooops!)Thirdly, just a particular worry of mine. Passing enumerated types in C++ works differently than in Delphi. In C++ it is not really clear from the MSDN doco how they are passed, but in Delphi"NoteEnumerated constants without a specific value have RTTI:" from the help file. I'm worried that sending uninitialized enumerated types in Delphi may have side effects.Finally: I tried nesting the records as you have done:SIMCONNECT_RECV_EXCEPTION = record Header: TSimConnectRecv; dwException: DWORD; dwSendID: DWORD; dwIndex: DWORD; end;But I think I will return my records to copied fields as the nesting is going to cause further dereferencing in the programming. I've always agreed with the guy (name escapes me) who design the SR71 "Simplicate and add lightness".Hope this helps. BTW I also will post my version when it's fit for human consumption.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...