freepascal

FPC : RTTI on records

会有一股神秘感。 提交于 2019-12-10 14:37:18
问题 This is my first time on this site. Usually, I have no problem to found replies in the old posts but I don't success with my actual problem. I would like to know how use RTTI functions to know at running time the properties/members of a record under Lazarus/FPC? I know how to do it for a class (Tpersistent descendant and published properties) but not for FPC. Some links indicates how to do it under Delphi (From D2010), but I don't know how to transpose it under Lazarus. Thanks in advance for

Casting between parent and child classes in delphi

夙愿已清 提交于 2019-12-10 06:28:34
问题 I'm writing some software that targets two versions of very similar hardware which, until I use the API to initialize the hardware I'm not able to know which type I'll be getting back. Because the hardware is very similar I planned to have a parent class (TParent) that has some abstract methods (for where the hardware differs) and then two child classes (TChildA, TChildB) which implement those methods in a hardware dependent manner. So I would first instantiate an object of TParent check what

A Delphi/FreePascal lib or function that emulates the PHP's function parse_url

半腔热情 提交于 2019-12-08 22:34:19
问题 I'm doing a sitemap producer in Object Pascal and need a good function or lib to emulate the parse_url function on PHP. Does anyone know of any good ones? 回答1: Freepascal has the unit URIParser with the ParseURI function. An example how to use it can be found in one of the example in Freepascal's source. Or an old example which is somewhat easier to understand. 回答2: I am not familiar with the parse_url function on PHP, but you might try the TIdURI class that is included with Indy (which in

Free Pascal for Android on MIPS

萝らか妹 提交于 2019-12-08 19:34:05
问题 Trying to port a Delphi library to Android. Free Pascal has Android/ARM support - a prebuilt compiler for Windows is available. However, Android NDK now supports MIPS and x86 as well. What's the status of support for those in FPC? For now, my project is more or less CPU agnostic - the native bits are built for all four supported architectures. Don't want to let go of that. I'm not after the full cycle of Android development in Pascal - just an algorithm library that does no I/O. I tried

How are pascal strings represented in memory?

不问归期 提交于 2019-12-08 10:12:09
问题 How are pascal strings laid out in memory? I read: http://www.freepascal.org/docs-html/ref/refsu12.html It says that strings are stored on the heap and reference counted. To figure out where the length and reference was stored, I created a string and did tests on it a lot: type PInt = ^Integer; var str: String; begin str := 'hello'; writeln(PInt(@str[1]) - (sizeof(integer) * 1)); //length writeln(PInt(@str[1]) - (sizeof(integer) * 2)); //reference count end. The first one prints the length

How do I detect if stdin or stdout is redirected in FreePascal under Windows?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 00:41:08
问题 I need to know whether stdin or stdout has been redirected for a console application using the latest FPC (v3.0.0) In the old Turbo Pascal days, I had a function written in assembly that did this. See below: { ************************************************************** * Routine : RedirectedStd * * Purpose : Return Yes (True) if standard handle is being * * : redirected. * * Note(s) : Even though handle can take any handle value, * * : the function will be meaningful only for the * * :

How to search an array of bytes for “StringA”?

一笑奈何 提交于 2019-12-07 13:48:13
问题 Using FreePascal (or Delphi if no FP examples), given a 2048 byte buffer that is as an "array of bytes", how can I search the buffer for "StringA"? var Buffer : array[1..2048] of byte; ... repeat i := 0; BlockRead(SrcFile, Buffer, SizeOf(Buffer), NumRead); // Now I want to search the buffer for "StringA"? ... Thankyou 回答1: I think this will work in fpc without extra Unicode/AnsiString conversion : function Find(const buf : array of byte; const s : AnsiString) : integer; //returns the 0-based

Unable to enter critical section

房东的猫 提交于 2019-12-07 10:34:39
问题 Why is it imposible to enter critical section without Sleep(1)? type TMyThread = class(TThread) public procedure Execute; override; end; var T: TMyThread; c: TRTLCriticalSection; implementation procedure TForm1.FormCreate(Sender: TObject); begin InitializeCriticalSection(c); T := TMyThread.Create(false); end; procedure TMyThread.Execute; begin repeat EnterCriticalSection(c); Sleep(100); LeaveCriticalSection(c); sleep(1); // can't enter from another thread without it until false; end;

consuming C dlls with Delphi

走远了吗. 提交于 2019-12-07 09:18:14
问题 I have a Dll function with this signature: UInt32 Authenticate(uint8 *Key); I'm doing this on Delphi: function Authenticate(Key:string) : UInt32; external 'mylib.dll' name 'Authenticate'; But always, the function return 10 (error code) and the application brakes :\ There is a way to do this right? UPDATE: thanks guys! you're the best! 回答1: There are some problems with your code. 1) uint8 is the equivilent of Byte in Delphi, not String . 2) the C code is using the compiler's default calling

GUI Only By Using FPC

我们两清 提交于 2019-12-07 06:28:45
问题 I want to know how I can develop GUI applications(32 Bits) without using Delphi language(Object Pascsl), only by using FPC with Lazarus installed(Pascal). Thanks. 回答1: Use a widget set directly. Look at e.g. the examples in packages/gtk2 for unix, or the windows win32api usage demo. (demo\win32 in the FPC win32 installation) But not using lazarus makes you lose platform independance, and a lot of ease. Looking how lazarus does it, is still a possibility. A second option is https://github.com