[fpc-pascal] How do I pass a call back Class and its method to an external library *.so file writting in C++

2024-10-03 Thread Dennis via fpc-pascal

Dear All,

I am given an API linux library *.so file written in C++.
It was expected to be consume by a program written in C++.
However, I would like to write such a program in Free Pascal.

The given header file is:
#ifndef ApiProxyWrapperReplyH
#define ApiProxyWrapperReplyH
//---
#include 
#include "SPApiProxyDataType.h"
class ApiProxyWrapperReply {

public:
    ApiProxyWrapperReply(void){};
    ~ApiProxyWrapperReply(void){};
    virtual void OnLoginReply(char *user_id, long ret_code,char 
*ret_msg) = 0;

    virtual void OnConnectedReply(long host_type,long con_status) = 0;
    virtual void OnApiOrderRequestFailed(tinyint action, const 
SPApiOrder *order, long err_code, char *err_msg) = 0;
    virtual void OnApiOrderReport(long rec_no, const SPApiOrder *order) 
= 0;

    virtual void OnApiOrderBeforeSendReport(const SPApiOrder *order) = 0;
    virtual void OnAccountLoginReply(char *accNo, long ret_code, char* 
ret_msg) = 0;
    virtual void OnAccountLogoutReply(char *accNo, long ret_code, char* 
ret_msg) = 0;

    virtual void OnAccountInfoPush(const SPApiAccInfo *acc_info) = 0;
    virtual void OnAccountPositionPush(const SPApiPos *pos) = 0;
    virtual void OnUpdatedAccountPositionPush(const SPApiPos *pos) = 0;
    virtual void OnUpdatedAccountBalancePush(const SPApiAccBal 
*acc_bal) = 0;
    virtual void OnApiTradeReport(long rec_no, const SPApiTrade *trade) 
= 0;

    virtual void OnApiPriceUpdate(const SPApiPrice *price) = 0;
    virtual void OnApiTickerUpdate(const SPApiTicker *ticker) = 0;
    virtual void OnPswChangeReply(long ret_code, char *ret_msg) = 0;
    virtual void OnProductListByCodeReply(long req_id, char *inst_code, 
bool is_ready, char *ret_msg) = 0;
    virtual void OnInstrumentListReply(long req_id, bool is_ready, char 
*ret_msg) = 0;

    virtual void OnBusinessDateReply(long business_date) = 0;
    virtual void OnApiMMOrderBeforeSendReport(SPApiMMOrder *mm_order) = 0;
    virtual void OnApiMMOrderRequestFailed(SPApiMMOrder *mm_order, long 
err_code, char *err_msg) = 0;
    virtual void OnApiQuoteRequestReceived(char *product_code, char 
buy_sell, long qty) = 0;
    virtual void OnApiAccountControlReply(long ret_code, char *ret_msg) 
= 0;
    virtual void OnApiLoadTradeReadyPush(long rec_no, const SPApiTrade 
*trade) = 0;

};

#endif

I am expected to create and pass an instance of such class 
ApiProxyWrapperReply in my calling program

 via a function
void SPAPI_RegisterApiProxyWrapperReply(ApiProxyWrapperReply* 
apiProxyWrapperReply);


and the external library will then call the various methods of 
ApiProxyWrapperReply  as 'call-back' functions when needed.


I consulted co-pilot but it failed to teach me how to do so in a Free 
Pascal program calling such an external library.


Please kindly help.

Dennis Poon

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Legitimate use of for and break

2023-06-20 Thread Dennis Lee Bieber via fpc-pascal
On Tue, 20 Jun 2023 14:05:04 +0700, Hairy Pixels via fpc-pascal
 declaimed
the following:

>
>Educators continuously have stupid ideas that don't work out as intended in 
>the real world.  I would love to see them make a real program that does 
>something difficult and not use early breaks.
>
>I assume them they forbid early exits in functions also or is the loop special 
>for them?
>

One-IN/One-OUT was a tenet of Structured Programming as used in the
late 1970s/early 1980s -- and yes, it also applied to subprograms
(functions and routines both for those languages that differentiated) and
IF statements.

This is also about the same time that Chapin/Nassi-Schneiderman charts
were developed to be used in place of free-form flow-charts. N-S chart
elements enforced a one-in/one-out diagramming of the logic (no GOTO
equivalent). If it required nesting IF statements to avoid ad-hoc GOTO, so
be it. Mapping those structures to "unstructured" languages (COBOL 74,
FORTRAN IV, BASIC, etc.) might require reverting to GOTO -- but an
organization's programming standards guidelines would define exactly how a
structured entity would be mapped, and could thereby be reviewed for
compliance.

{structured}
if condition then
do stuff
else
do other stuff
endif

{FORTRAN IV}
if .not. (condition) then goto {elselabel}
do stuff
goto {endiflabel}
{elselabel} continue
do other stuff
{endiflabel} continue

[FORTRAN "CONTINUE" is a NOP statement, often used as the target of a GOTO
as one could edit the subsequent actions without having to keep moving the
label from statement to statement]



BREAK/CONTINUE tended to come later, when they were deemed a safe (ie;
structured) alternative to the GOTO statement.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Pause Key

2023-04-15 Thread Dennis Lee Bieber via fpc-pascal
On Sat, 15 Apr 2023 14:23:12 +0300, Nikolay Nikolov via fpc-pascal
 declaimed
the following:

>Actually, the Linux console (but not X11!) uses Scroll Lock to pause the 
>console output, pretty much the same way DOS and BIOS used the Pause 
>key. Why didn't Linus Torvalds use the Pause key is beyond me.
>

Why didn't either use the long established X-on/X-off /
convention?

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-03 Thread Dennis Lee Bieber via fpc-pascal
On Mon, 03 Apr 2023 20:55:43 +0200, Bo Berglund via fpc-pascal
 declaimed
the following:

>I just tested by writing four 0x00 bytes in a row, then verifying that the
>memory read shows these, then writing other data and again verifying that the
>data is there.
>

Which may only mean the chip has an on-board controller and memory
buffer, and the chip is performing the page level erase followed by buffer
write.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

2023-04-02 Thread Dennis Lee Bieber via fpc-pascal
On Sun, 02 Apr 2023 16:16:46 +0200, Bo Berglund via fpc-pascal
 declaimed
the following:


>
>
>Byte Write

>a  location  within  a  64  byte  page.  A  byte  following  the
>address bytes will be interpreted as data. The data will be
>loaded into the Page Write Buffer and will eventually be
>written to memory at the address specified by the 14 active

>The Master then starts the internal Write cycle by issuing a
>STOP condition (Figure 6). During the internal Write cycle
>(tWR), the SDA output will be tri-stated and additional Read
>or Write requests will be ignored (Figure 7).
>--
>
This sounds suspiciously like one is expected (or is able) to write
multiple bytes /within/ the "page" via multiple address/data operations,
and have all those bytes "burned" into the memory using a single "stop"
operation.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Lazarus 2.0.10 FPC 3.2.0 TFPHTTPClient no longer supports https

2020-08-05 Thread Dennis



Michael Van Canneyt wrote:



On Wed, 5 Aug 2020, Dennis wrote:



Michael Van Canneyt wrote:

On Wed, 5 Aug 2020, Dennis wrote:

After upgrading to Lazarus 2.0.10 FPC 3.2.0 , my existing code 
using TFPHTTPClient.Get('https://api.telegram.org/bot')

returns the error "No SSL Socket support compiled in"

How can I fix it?


Simply add one of the units opensslsockets or gnutlssockets to the uses
clause of the program.


I added gnutlssockets  but when calling Get, i got this error:

Could not load library: libgnutls.so


Do you have gnutls installed, and does the symbolic link exist ?


I have not installed gnutls. The machine is running windows 64.
So, the error message simply means  the *.dll files of gnutls are missing?

Dennis

--
This email has been checked for viruses by AVG.
https://www.avg.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Lazarus 2.0.10 FPC 3.2.0 TFPHTTPClient no longer supports https

2020-08-05 Thread Dennis


Michael Van Canneyt wrote:

On Wed, 5 Aug 2020, Dennis wrote:

After upgrading to Lazarus 2.0.10 FPC 3.2.0 , my existing code using 
TFPHTTPClient.Get('https://api.telegram.org/bot')

returns the error "No SSL Socket support compiled in"

How can I fix it?


Simply add one of the units opensslsockets or gnutlssockets to the uses
clause of the program.


I added gnutlssockets  but when calling Get, i got this error:

Could not load library: libgnutls.so

Please help.

Dennis Poon


--
This email has been checked for viruses by AVG.
https://www.avg.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Lazarus 2.0.10 FPC 3.2.0 TFPHTTPClient no longer supports https

2020-08-04 Thread Dennis
After upgrading to Lazarus 2.0.10 FPC 3.2.0 , my existing code using 
TFPHTTPClient.Get('https://api.telegram.org/bot')

returns the error "No SSL Socket support compiled in"

How can I fix it?

Dennis

--
This email has been checked for viruses by AVG.
https://www.avg.com

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Initial support for Custom Attributes

2019-07-13 Thread Dennis



Sven Barth via fpc-pascal wrote:

Hello together!

Today FPC has finally gained initial support for Custom Attributes. 
The work had initially been done by Joost van der Sluis almost 6 years 
ago and Svetozar Belic had adjusted the code for trunk. So thank you 
both for that work even if it took quite some time until it was 
finally integrated into trunk.



Thanks for the contribution.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] why isn't the 'exit' in the finally end clause executed?

2019-06-24 Thread Dennis

.

I seem to remember this was a bug in the Win64 SEH support that was
fixed later on, but I can't find the bug report.

It's still the case on current trunk at least on Win64.



Since it might be a bug, I'd like to search for all occurrences of such 
combination in my projects.

How do I find it using regular expression ACROSS line breaks?
That is, how to find the following in Lazarus IDE?

finally
   .
   exit;
   .
end;

Thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] why isn't the 'exit' in the finally end clause executed?

2019-06-23 Thread Dennis

Using fpc 3.0.4, Lazarus 2.0, the following simple program

program tryfinally;

begin
  try
    Writeln('before finally');
  finally
 Writeln('inside finally. Before Exit');
 exit; //<why isn't it executed?
  end;
  Writeln('after try finally block');

end.


gives


P:\RAM64>tryfinally.exe
before finally
inside finally. Before Exit
after try finally block



I have tried putting the try finally block inside a procedure, the same 
happened.

program tryfinally;

procedure Test;
begin
    try
  Writeln('before finally');
    finally
   Writeln('inside finally. Before Exit');
   exit;
    end;
    Writeln('after try finally block');
end;

begin
  Test;

end.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] http://wiki.freepascal.org/ web site is totally blank

2019-06-07 Thread Dennis


DaWorm wrote:
There was a thread yesterday about issues with the servers.  This may 
be related.


Jeff

On Thu, Jun 6, 2019 at 4:58 AM Dennis <mailto:de...@avidsoft.com.hk>> wrote:


Does it only happen to me?



The web site is still blank.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] http://wiki.freepascal.org/ web site is totally blank

2019-06-06 Thread Dennis

Does it only happen to me?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] error in https://www.freepascal.org/docs-html/rtl/strutils/ansiindextext.htm

2019-05-08 Thread Dennis
I believe the red text below (in the url on the subject line) should be 
AnsiIndexText instead of AnsiIndexStr.



   Description

AnsiIndexStr matches AText against each string in AValues . If a match 
is found, the corresponding index (zero-based) in the AValues array is 
returned. If no match is found, -1 is returned. The strings are matched 
ignoring case.




Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] TThread.OnTerminate never called

2019-04-26 Thread Dennis



Sven Barth via fpc-pascal wrote:

Am 21.04.2019 um 18:22 schrieb Dennis:

I am using FPC 3.0.4 Lazarus 2.00 on windows 64

I created a subclass of TThread and found out that the 
TThread.OnTerminate event was never called (I already assigned it).
Also, I search the source code of TThread in classeh.inc and found 
that there was no calling of FOnTerminate nor OnTerminate


Is it supposed to be a dummy place holder?
I don't use Delphi any more. Is this behaviour the same as Delphi?

Thanks in advance.


How did you test it? OnTerminate is called using Synchronize so if you 
use a command line program to test it you need to make sure to call 
CheckSynchronize otherwise you'll never see it being called. In a LCL 
program that should work without any further action.


I am using the debugger to break on the Event assigned to OnTerminate.  
That breakpoint was never reached.

I am using the FpDebug internal Dwart-debugger (beta)
Can you tell me what the code of calling synchronize(OnTerminate) is?  I 
cannot find it in the FPC source.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] TThread.OnTerminate never called

2019-04-21 Thread Dennis

I am using FPC 3.0.4 Lazarus 2.00 on windows 64

I created a subclass of TThread and found out that the 
TThread.OnTerminate event was never called (I already assigned it).
Also, I search the source code of TThread in classeh.inc and found that 
there was no calling of FOnTerminate nor OnTerminate


Is it supposed to be a dummy place holder?
I don't use Delphi any more. Is this behaviour the same as Delphi?

Thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Web Server Written in Free Pascal?

2019-03-31 Thread Dennis



Michael Van Canneyt wrote:



On Wed, 27 Mar 2019, Anthony Walter wrote:


No I haven't. I will check it out thank you. I just thought my
implementation and interface was rather clean, simple, and easy to
understand.


I hope you'll be pleasantly surprised by the multitude of webprogramming
tools available in FPC. This is an area of very active development, the
latest addition is a complete REST bridge for SQLDB.



Can you share the link of REST bridge for SQLDB?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] how to make a type private to the unit but not defining it in the implementation section?

2019-03-07 Thread Dennis Poon



Anthony Walter wrote:

type
  _PrivateData = class
    private type THidden = record Name: string; end;
  end;

... and later in the implementation section of the same unit ...

var H: _PrivateData.THidden; begin H.Name := 'Hello'; end;



But that will have the same problem of extra long method declaration name
  procedure _PrivateData.THidden.Method1;
  begin
  end;


Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] how to make a type private to the unit but not defining it in the implementation section?

2019-03-07 Thread Dennis

unit frproxyserver;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Grids,
  frBase;

type

  TMyStringGrid=class(TStringGrid) //how to I make this class visible 
only to this unit?

  public
  end;

  { TProxyServerFrame }

  TProxyServerFrame = class(TBaseFrame)
    Panel_Top: TPanel;
    StringGrid1: TMyStringGrid;
  private

  public

  end;

implementation

{$R *.lfm}

end.

=
My reason is I don't want to pollute the name space but if I put the 
declaration of TMyStringGrid in the implementation section, it cannot be 
used by the field in the class declaration of TProxyServerFrame.


if there a compiler directive that I can put around
TMyStringGrid to make it only visible to the unit frproxyserver?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Anyone uses Synapse trunk version instead of the official 2012 release 40?

2019-02-25 Thread Dennis
I noticed there are quite many changes in the sourceforge.net project 
especially in terms of SSL fixes.

I want to use the trunk but worry that it is not stable yet.

Anyone uses the 2018-08-22 trunk version stably for a while?

I tried asking it on the synapse emailing list but got no reply.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] how to loadlibrary in a specific folder in windows 64?

2019-02-08 Thread Dennis

I am using FPC 3.0.4 Lazarus.
I tried to use synapse with ssl and the unit ssl_openssl_lib 's 
initialization

   runs InitSSLInterface
   which calls
  SSLLibHandle := LoadLib(DLLSSLName);
  SSLUtilHandle := LoadLib(DLLUtilName);

where the var are defined as
  DLLSSLName: string = 'ssleay32.dll';
  DLLUtilName: string = 'libeay32.dll';

it works well.

However, my program also need to call another dll (library) which comes 
with its own set of
ssleay32.dll and libeay32.dll which cannot be used by synapse 's 
ssl_openssl_lib.
ssl_openssl_lib can only loadlibrary successfully the binary dll files 
from https://indy.fulgan.com/SSL/


These clashing of ssl dll is causing me problems.

I tried to put the 2 sets of dll in 2 folders and call 
LoadLibrary('folder1\ssleay32.dll') but  LoadLibrary does not accept any 
file path.  If there is a file path in the name, it just fails.


Please help.

Dennis



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] when will the size of an enumerated type change?

2019-01-09 Thread Dennis

Type
   TComparisonMode = (cmThisOnly, cmThisAndThat, cmThisOrThat);


TMyClass = class
public
var
   ComparisonMode : TComparisonMode;
end;


I discovered that, the sizeof(ComparisonMode) seem to be different 
depending on whether the type TComparisonMode is defined in the same 
unit file or in another unit file.


Is that possible?

I cannot create a simple test file to test it because the problem only  
appears in my big project.


Does FPC always produce a 4 byte variable for an enumerated types?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Rest in peace Martin Schreiber

2018-12-31 Thread Dennis
Just wondering whether the deceased's family requires any financial 
assistance?

If yes, maybe we can throw a fund raiser.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Rest in peace Martin Schreiber

2018-12-26 Thread Dennis



Graeme Geldenhuys wrote:

Hi everybody,

Today I became aware of very sad news. Martin Schreiber, author of the
MSEide+MSEgui project, has unexpected succumbed of cardiac arrest on 29
November 2018. He was an avid FPC and Pascal Language supporter, and
very knowledgeable in his field. He will definitely be missed by many.
Our hearts and prayers go out to his family and friends.

Rest in peace Martin Schreiber.


Regards,
   Graeme


That is horrible news. How can someone pass away so suddenly? So sad.
My condolences to his friends and family.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] How to codesign my FPC program

2018-10-30 Thread Dennis
When my users run my FPC compiled 64 bit program, sometimes, they are 
warned that my exe was not published or known.
I am thinking, if I purchase a code signing certificate and sign my exe, 
will windows remove that warning?


I googled and found the cheapest one is form Comodo at USD 75/year.

https://codesigncert.com/cheapcodesigning

I am totally new to this.  Can that USD75 certificate achieve my goal?
After I get the certificate, do you need to use any special software to 
sign my exe?


Seems like Visual Studio can do it but I am using Lazarus.

Any feedback is welcome.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Cannot use SQLite 64 bit dll

2018-10-21 Thread Dennis

A simple test here with a SQLite3Connection works without problems.


Do you get an exception if the library is *not* located in the same 
folder? In that case it loaded correctly and something else must be 
the problem.


Regards,
Sven
___
I deleted the library from the exe folder and surprisingly it behaved 
exactly the same. it just waited a few seconds before quitting silently. 
No except was thrown.
I suspect the exe tries to link to the sqlite dll somewhere in the 
search path, which is a 32 bit version, so it quits silently after 
finding out it is not a 64 bit dll.


How can I force SQLite3Connection to first look for the dll in the exe 
folder instead of from the search path?


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Cannot use SQLite 64 bit dll

2018-10-19 Thread Dennis
Using Lazarus and FPC and sqlite3conn unit, I can use the sqlite3.dll on 
windows without problem.


However, when I try to convert my project to win 64, it just fail 
without any warning.


I am using
    FPC 3.1.1 Revision 63034
    Lazarus 1.9.0
    both are Win64

I download the win 64 bit version of sqlite3.dll from
https://www.sqlite.org/2018/sqlite-dll-win64-x64-3250200.zip
and place it in the same folder as my exe.

The project compiles without errors nor warning.

But when I run the exe, it just waits a few seconds and then quits silently.

I tried debugging it and set breakpoints at all of  the following in 
sqlite3.inc

function TryInitializeSqlite(const LibraryName: UnicodeString): Integer;
function InitialiseSQLite:integer;
function  InitializeSQLiteANSI(const LibraryName: AnsiString):integer;
function  InitializeSQLite(const LibraryName: UnicodeString) :integer;
function  InitialiseSQLite(const LibraryName: UnicodeString):integer;

and the following in SQLite3Conn:
class function TSQLite3ConnectionDef.DefaultLibraryName: string;
class function TSQLite3ConnectionDef.LoadedLibraryName: string;
class function TSQLite3ConnectionDef.LoadFunction: TLibraryLoadFunction;

However, the debugger did not stop at all at any of them.

What could possibly be the cause of the problem?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] any free pascal standard function to compare a string against an array of string?

2018-10-10 Thread Dennis

is there a function like
  if    IsOneOf('subtext', ['abc','cde','fecg','hig'])   then begin
...
end;

is there such a function IsOneOf(TheSubString : String; const TheStrings 
: array of String) : Boolean

?
if yes, what is its name and unit?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Announcement GLPT

2018-09-26 Thread Dennis Poon



Darius Blaszyk wrote:
On Tue, Sep 25, 2018 at 5:21 PM Dennis <mailto:de...@avidsoft.com.hk>> wrote:


I tried it but found that drawing text in OpenGL seems to be
problematic.
Is there anyway to draw text using windows' existing font? Or is
there a
library for nicer vector based font?


There is a unit called uglyfont.pas included in Lazarus. I ported it 
some time ago for an imgui implementation example. This is a simple 
vector font. You can also implement a freetype font fairly easy. In 
fact I can share some code. Just search for NeHe and you will find it 
online as well.


Although GLUT came with standard fonts I am not inclined to include a 
font in GLPT soon. Same for menu, UI and other drawing stuff. This 
should be handled one level higher up.


I am writing a Chinese program and the Chinese character set is huge 
with many thousand of characters, and each character has many strokes. I 
think the work required is too daunting and the improvement in speed is 
not that much for my simple chart plotting use.


I will stay with Lazarus UI for the moment. In future, I might explore 
fpGUI instead.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Announcement GLPT

2018-09-25 Thread Dennis



Anthony Walter wrote:

Dennis,

If you want to embed OpenGL in your window, then there is already 
TOpenGLControl. It's included with Lazarus and is in the components 
folder.


More here:


Thanks a lot.
I tried it but found that drawing text in OpenGL seems to be problematic.
Is there anyway to draw text using windows' existing font? Or is there a 
library for nicer vector based font?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Announcement GLPT

2018-09-25 Thread Dennis

Thanks for your contribution.
Just tried out your sample, they are nice.


How can I use opengl within my lazarus UI program?

I want to embed such an opengl window inside a TPanel, and in its Paint 
method, do the opengl rendering. Is that possible?  How?


Dennis


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] How is interface variable implemented?

2018-08-24 Thread Dennis

if I have this test program below:

program testi;
{$INTERFACES CORBA}
uses sysutils;
type
  IInterfaceA = interface
 procedure Increment ;
  end;

  { TObjectA }

  TObjectA = class(IInterfaceA)
    Value : Int64;
    procedure Increment;
  end;
var
  c : int32;
  i : IInterfaceA;
  obj : TObjectA;
  aTime : TDateTime;

{ TObjectA }

procedure TObjectA.Increment;
begin
  Inc(Value);
end;

begin
  obj := TObjectA.Create;
  try
    aTime := now;
    for c := 1 to 1 do
    obj.Increment;
    aTime := now - aTime;
    Writeln('Object call Time Taken Seconds:', aTime*24*60*60);
  finally
    FreeAndNil(obj);
  end;

  obj := TObjectA.Create;
  try
    aTime := now;
    i := obj;
    for c := 1 to 1 do
    i.Increment;
    aTime := now - aTime;
    Writeln('Interface call Time Taken Seconds:', aTime*24*60*60);
  finally
    FreeAndNil(obj);
  end;
  Readln;
end.


The run results:
Object call Time Taken Seconds: 2.1899964194744825E-001
Interface call Time Taken Seconds: 2.799001622200E-001

so, the time difference is about 27%


My question is, where is this extra time spent?

I am assuming an interface variable has a table with entries storing ( 
pointer to the object instance AND an offset of method address in the 
Virtual Method Table of that object.)


Am I correct?

What is the memory occupied by the interface variable?
I know the sizeof(i) = 8 (in 64 bit windows), but what is the size of 
the instance?


I cannot find any of this info on the web.

Thanks for your answer in advance.

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] why can't we define class operator for old fashion object type, but ok for 'advanced record' type?

2018-08-16 Thread Dennis Poon



Sven Barth via fpc-pascal wrote:

Am 15.08.2018 um 10:59 schrieb Dennis:
Why class operator is accepted for advanced records but not old 
fashion object???
Because objects are not records. Internally they are handled more 
closely to classes than records.


Would it be too hard to also implement class operators for old fashion 
objects?  That will be very  nice.


Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] why can't we define class operator for old fashion object type, but ok for 'advanced record' type?

2018-08-15 Thread Dennis



Michael Van Canneyt wrote:



On Wed, 15 Aug 2018, Dennis wrote:

I was trying to use a generic class TDictionary  with type T. This 
class has a method that compares a variable of T with another one.


When I specialize a class using this TDictionary with a type:

TSecurity = object
  
end;


e.g. TNewDict = class(TDictionary);

it raise a compiler complaining that my TSecurity type has no 
operator = defined.


But when I try to add like this:

TSecurity = object
  
class operator =  (constref aLeft, aRight: TSecurity ): Boolean; 
//<---compiler Error: Procedure or Function expected


end;


Did you try creating an "old-fashioned" = operator ?

Something like

Operator = (l,r : TSecurity) z : boolean;

begin
  // compare here
end;



Just tried.
It complained:   Fatal: Syntax error, "IMPLEMENTATION" expected but 
"identifier OPERATOR" found


Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] why can't we define class operator for old fashion object type, but ok for 'advanced record' type?

2018-08-15 Thread Dennis
I was trying to use a generic class TDictionary  with type T. This 
class has a method that compares a variable of T with another one.


When I specialize a class using this TDictionary with a type:

TSecurity = object
  
end;


e.g. TNewDict = class(TDictionary);

it raise a compiler complaining that my TSecurity type has no operator = 
defined.


But when I try to add like this:

TSecurity = object
  
class operator =  (constref aLeft, aRight: TSecurity ): Boolean; 
//<---compiler Error: Procedure or Function expected


end;


However, the following is OK
{$MODESWITCH advancedrecords}
TSecurity = record
  
class operator =  (constref aLeft, aRight: TSecurity ): Boolean; //<---OK

end;


Why class operator is accepted for advanced records but not old fashion 
object???


I cannot use advance record because it does have inherit methods. I need 
method inheritance for my object.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Will moving from due core CPU to 6 Core CPU of the same clock speed improve the speed of FPC compiling?

2018-08-07 Thread Dennis Poon



Martin wrote:


Out of interest, how long does it take you to compile your project?

Only 20 seconds. But sometimes, when I modify some units used by other 
units which are in turn used by other units, FPC throws the following 
exception when I compile (not build)

uspdata.pas(228,50) Error: Compilation raised exception internally

When that happens, I have to build the entire project, and that takes 
much longer.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Will moving from due core CPU to 6 Core CPU of the same clock speed improve the speed of FPC compiling?

2018-08-06 Thread Dennis

I have been using Intel i3 Dual Core CPU @3.4 GHz for a few years.
If I upgrade my computer and CPU to Intel Core i5 6-core @3.6GHz,
will the speed of FPC compilation improve noticeably?

Since FPC seems to be single threaded, I wonder whether 0.2GHz increase 
in clock speed will make any noticeable improvement in speed.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-24 Thread Dennis Poon



Sven Barth via fpc-pascal wrote:
Dennis mailto:de...@avidsoft.com.hk>> schrieb 
am Mo., 23. Juli 2018, 12:24:


Is this kind of enumerated type with constant assignment not
supported
by FPC 3.0.4?

   TMonthType = (January=1, February, May=5,June, July);


The enumeration type itself is supported, however TypeInfo() and thus 
GetEnumName() and friends are not.



No only that, the following also gives error
  for a in TMonthType do
 begin
   //a won't be assigned the proper values
    end;

Regards,
Sven


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] No type info available for this type (Enumerated type with constant assignment)

2018-07-23 Thread Dennis
I am trying out the examples at 
http://wiki.freepascal.org/Enumerated_types but
The following simple program will raise compiler error "No type info 
available for this typ"


I am using Lazarus 1.8.0  FPC 3.0.4   x86_64-Win64-win32/win64


program testenum;
uses typinfo, classes, sysutils;
type
  TMonthType = (January=1, February, May=5,June, July);

var i : int32;
    s : String;
begin
  for i := Ord(Low(TMonthType)) to Ord(High(TMonthType)) do
    begin
   s:= GetEnumName(TypeInfo(TMonthType), Ord(i)); <- compiler error 
pointed at the word TypeInfo

   Writeln(i.ToSTring+' -> '+s);
    end;
  readln;
end.



However, if I change to
  TMonthType = (January, February, May,June, July);

The compiler error will disappear.

Is this kind of enumerated type with constant assignment not supported 
by FPC 3.0.4?


  TMonthType = (January=1, February, May=5,June, July);

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How to translate Delphi Assembly MOV EAX,[EBP+4]

2018-07-18 Thread Dennis

Thanks.

So the following will give an address+frame of the calling routine ?
    get_caller_addr(get_frame),  get_caller_frame(get_frame)

Dennis

Sven Barth via fpc-pascal wrote:
Dennis mailto:de...@avidsoft.com.hk>> schrieb 
am Mi., 18. Juli 2018, 17:19:


The following delphi code when compiled by FPC, raised these errors:
Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1,
Errors: 10, Warnings: 2
StrBuffer.pas(100,19) Error: Unknown identifier "EAX"
StrBuffer.pas(100,23) Error: Assembler syntax error in operand
StrBuffer.pas(100,24) Error: Unknown identifier "EBP"
StrBuffer.pas(100,29) Error: Invalid constant expression
StrBuffer.pas(100,29) Error: Invalid reference syntax
StrBuffer.pas(100,29) Warning: No size specified and unable to
determine
the size of the operands, using DWORD as default
StrBuffer.pas(207,19) Error: Unknown identifier "EAX"
StrBuffer.pas(207,23) Error: Assembler syntax error in operand
StrBuffer.pas(207,24) Error: Unknown identifier "EBP"
StrBuffer.pas(207,29) Error: Invalid constant expression
StrBuffer.pas(207,29) Error: Invalid reference syntax
StrBuffer.pas(207,29) Warning: No size specified and unable to
determine
the size of the operands, using DWORD as default

Can anyone help me?

class procedure TStrBuffer.Error(const Msg: string; Data: Integer);

   function ReturnAddr: Pointer;
   asm
   MOV EAX,[EBP+4]
   end;

begin
   raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;
end;


There are two ways to solve this.

The first one is an easy one, however the code still won't be platform 
independent due to the assembly code. For this simply add "{$asmmode 
intel}" at the top.


The second solution is cross platform and with correct checks also 
Delphi compatible:


=== code begin ===
raise EListError.CreateFmt(Msg, [Data]) at
{$ifdef fpc}
get_caller_addr(get_frame),
get_caller_frame(get_frame)
{$else}
ReturnAddr
{$endif} ;
=== code end ===

Disable the ReturnAddr function also with "{$ifndef fpc}...{$endif}" 
and you should be set.


Regards,
Sven


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] How to translate Delphi Assembly MOV EAX,[EBP+4]

2018-07-18 Thread Dennis

The following delphi code when compiled by FPC, raised these errors:
Compile Project, Target: lib\x86_64-win64\Project1.exe: Exit code 1, 
Errors: 10, Warnings: 2

StrBuffer.pas(100,19) Error: Unknown identifier "EAX"
StrBuffer.pas(100,23) Error: Assembler syntax error in operand
StrBuffer.pas(100,24) Error: Unknown identifier "EBP"
StrBuffer.pas(100,29) Error: Invalid constant expression
StrBuffer.pas(100,29) Error: Invalid reference syntax
StrBuffer.pas(100,29) Warning: No size specified and unable to determine 
the size of the operands, using DWORD as default

StrBuffer.pas(207,19) Error: Unknown identifier "EAX"
StrBuffer.pas(207,23) Error: Assembler syntax error in operand
StrBuffer.pas(207,24) Error: Unknown identifier "EBP"
StrBuffer.pas(207,29) Error: Invalid constant expression
StrBuffer.pas(207,29) Error: Invalid reference syntax
StrBuffer.pas(207,29) Warning: No size specified and unable to determine 
the size of the operands, using DWORD as default


Can anyone help me?

class procedure TStrBuffer.Error(const Msg: string; Data: Integer);

  function ReturnAddr: Pointer;
  asm
  MOV EAX,[EBP+4]
  end;

begin
  raise EListError.CreateFmt(Msg, [Data])at ReturnAddr;
end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] How to use Google Protocol Buffer

2018-07-09 Thread Dennis

To connect to a server, I need to use Google's Protocol Buffer format.

The only workable parser to convert the protocol definition file to 
pascal reader/writer source code is:


the ProtoBufCodeGen in
https://github.com/fundamentalslib/fundamentals5/releases

Still, there is no documentation on how to call the generated codes.

For example, it generated these:

procedure RequestRecordInit(var A: TRequestRecord);
procedure RequestRecordFinalise(var A: TRequestRecord);

function  pbEncodeDataRequestRecord(var Buf; const BufSize: Integer; 
const A: TRequestRecord): Integer;


function  pbDecodeValueRequestRecord(const Buf; const BufSize: Integer; 
var Value: TRequestRecord): Integer;


function  pbEncodeFieldRequestRecord(var Buf; const BufSize: Integer; 
const FieldNum: Integer; const A: TRequestRecord): Integer;
procedure pbDecodeFieldRequestRecord(const Field: 
TpbProtoBufDecodeField; var Value: TRequestRecord);



I could call pbEncodeDataRequestRecord to convert the TRequestRecord to 
a stream of byte and store in the Buf
but there is not a routine to convert it back from a stream of bytes to 
the TRequestRecord.


The only seemingly useful routine pbDecodeValueRequestRecord, when 
called with the Buf generated by pbEncodeDataRequestRecord will raise 
exception "Invalid buffer "


Any help?

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] List of chars for case

2018-07-01 Thread Dennis



Ryan Joseph wrote:

Is there a way to make a constant for a list of chars which I can use in a case 
statement? I’ve got a bunch of code duplication happening I’d like to clean up.

const
   TChars = ('[', ']', '(', ')', '{', '}', '=', ‘:’);


case c of
   TChars:
 ...


Regards,
Ryan Joseph



  case c of
     '[', ']', '(', ')', '{', '}', '=', ':' : result := true;
  end;



Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Realtime and freepascal???

2018-05-31 Thread Dennis



Darius Blaszyk wrote:

Hi,

For a hard real-time project I am considering using freepascal. As 
this is my first endeavour in real-time I would like to ask the 
community on their experiences. Is FPC suitable for this kind of 
applications? If so what commercially available boards are out there? 
I believe a beagle bone for instance is capable of doing realtime 
applications because of the PRU. Any other credit card size boards 
worthwhile investigating? What RTOS do people have good experience 
with in combination with freepascal?


I am not sure Beagle Bone is a good choice because it seemed to have 
supply problem for many years. It is hard to purchase large quantity of it.
In the past, I have use raspberry Pi connected to many simple devices 
via a serial bus. The PI acts as a server to accept commands from the 
internet and forward them to the devices on the serial bus and pass back 
the responses to the internet.  The software was written in FPC.


Also, check out this https://ultibo.org/
Which is an embedded OS written in FPC, so you just modify the source 
code to include your application and recompile a new embedded OS for use 
with raspberry Pi.
That way, it has lower latency and lower RAM requirement than running 
your FPC program on top of the Linux OS.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Stack alias for ARC like memory management?

2018-04-25 Thread Dennis



Michael Van Canneyt wrote:


I want the same for pascal.

But I really still need to see convincing evidence that language 
features contribute to productivity.


Available libraries for common programming tasks - and I mean this on 
a high-level

level - are infinitely more important, so I don't need to get down to the
gory details of many tasks:

* Creating a PDF. * Creating a good-looking report from Data. * Have 
an API that reads google protocol data.

* A good ORM/OPF.
* Reading a smartcard.
* Access a Google,Facebook,Twitter, MS or what-have-you-not REST API. 
* A wizard that makes a Data entry form based on a TDataset or object.

* Classes to make a REST API.
* Classes to make/consume a SOAP service.
* Code that transforms a JSON structure to object classes plus the 
code to

* read/write the JSON.

These are things that make me win time.

I totally agree that available libraries like the above are what attract 
(or keep existing) users to Pascal, not some minor syntactical  sugar.

E.g.
  people new to AI will learn python just because there are ready 
libraries in AI callable by python.
  People new to statistics will learn R just because there are ready 
libraries of statistics in R.
  People new to iOS will learn swift because it allows them easily call 
all the libraries of iOS, not because swift is better than Pascal or Java.


It is about convenience.

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Where to download OpenSSL (for windows 64 bit) that is used by fphttpclient

2018-04-18 Thread Dennis
According to http://wiki.lazarus.freepascal.org/fphttpclient, I need the 
openssl library if I want to use fphttpclient for https://www.yahoo.com/


From the wiki, it went to https://wiki.openssl.org/index.php/Binaries 
for the binary dll but I tried the link https://indy.fulgan.com/SSL/  in 
the wiki and it did not work.


Anyone with a successful experience can give me a direct url for the 
openssl dll?


By the way, for those zip files I tried, although they are named 
xxx-win64, the dll contained in them are named ssleay32.dll and 
libeay32.dll.

Is that normal for a win64 bit dll to be named xxx32.dll?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] C header to Pascal , what is the type of ENUM?

2018-02-23 Thread Dennis

In C
ENUM_BEGIN( RetCode )
    /*  0 */  ENUM_DEFINE( TA_SUCCESS, Success ), /* No error */
    /*  1 */  ENUM_DEFINE( TA_LIB_NOT_INITIALIZE, LibNotInitialize 
), /* TA_Initialize was not sucessfully called */
    /*  2 */  ENUM_DEFINE( TA_BAD_PARAM, BadParam ), /* A parameter 
is out of range */
    /*  3 */  ENUM_DEFINE( TA_ALLOC_ERR, AllocErr ), /* Possibly 
out-of-memory */

    /*  4 */  ENUM_DEFINE( TA_GROUP_NOT_FOUND, GroupNotFound ),
    /*  5 */  ENUM_DEFINE( TA_FUNC_NOT_FOUND, FuncNotFound ),
    /*  6 */  ENUM_DEFINE( TA_INVALID_HANDLE, InvalidHandle ),
    /*  7 */  ENUM_DEFINE( TA_INVALID_PARAM_HOLDER, 
InvalidParamHolder ),
    /*  8 */  ENUM_DEFINE( TA_INVALID_PARAM_HOLDER_TYPE, 
InvalidParamHolderType ),
    /*  9 */  ENUM_DEFINE( TA_INVALID_PARAM_FUNCTION, 
InvalidParamFunction ),
    /* 10 */  ENUM_DEFINE( TA_INPUT_NOT_ALL_INITIALIZE, 
InputNotAllInitialize ),
    /* 11 */  ENUM_DEFINE( TA_OUTPUT_NOT_ALL_INITIALIZE, 
OutputNotAllInitialize ),
    /* 12 */  ENUM_DEFINE( TA_OUT_OF_RANGE_START_INDEX, 
OutOfRangeStartIndex ),
    /* 13 */  ENUM_DEFINE( TA_OUT_OF_RANGE_END_INDEX, 
OutOfRangeEndIndex ),

    /* 14 */  ENUM_DEFINE( TA_INVALID_LIST_TYPE, InvalidListType ),
    /* 15 */  ENUM_DEFINE( TA_BAD_OBJECT, BadObject ),
    /* 16 */  ENUM_DEFINE( TA_NOT_SUPPORTED, NotSupported ),
    /*   5000 */  ENUM_DEFINE( TA_INTERNAL_ERROR, InternalError ) = 5000,
    /* 0x */  ENUM_DEFINE( TA_UNKNOWN_ERR, UnknownErr ) = 0x
ENUM_END( RetCode )

The function in C is
TA_RetCode TA_EMA( int    startIdx,
   int    endIdx,
   const double inReal[],
   int   optInTimePeriod, /* From 2 to 10 */
   int  *outBegIdx,
   int  *outNBElement,
   double    outReal[] );

my question is, what should the type of TA_RetCode be in Pascal? Word (2 
byte) or LongWord (4 bytes)?


In short, is this pascal translation correct?
function TA_EMA(startIdx, endIdx : integer;
   const inReal : PDouble;
   optInTimePeriod : integer;
   var utBegIdx,
   outNBElement : integer;
   outReal : PDouble ) : Word;stdcall; external 
'ta_func.dll';


Note: the dll is 64-bit windows but I am not sure whether int should 
translate to Integer or Int64 in Pascal.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Is there a smart way to save/restore NotifyEvents and objects?

2018-02-02 Thread Dennis Poon



Sven Barth via fpc-pascal wrote:
Am 02.02.2018 17:53 schrieb "Dennis" <mailto:de...@avidsoft.com.hk>>:


I have list of objects which contains references to other objects.
I need to save all these objects to harddisk to be restored on a
latter day.

I know how to stream the data fields of these objects to a
TFileStream but the tricky part is these how to restore the object
references.

The only way I can think of is to assign unique IDs to each
objects and store these IDs to file.
When these objects are later restored, I used these IDs find the
actual objects and re-assign them back to the object references.

It is tedious. Is there a smarter way?

Also, there are some TNotifyEvent fields  e.g. OnClick, OnClose
etc.  How do I save and restore them from file?

Many thanks in advance.


If your objects inherit from TComponent and you use published 
properties you can use the streaming screen of the RTL.


I am curious how TComponent save and restore TnotifyEvent fields. Can 
you explain a little bit?

Also, what is 'streaming screen' of RTL? How to use it?

Thanks.

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Is there a smart way to save/restore NotifyEvents and objects?

2018-02-02 Thread Dennis

I have list of objects which contains references to other objects.
I need to save all these objects to harddisk to be restored on a latter day.

I know how to stream the data fields of these objects to a TFileStream 
but the tricky part is these how to restore the object references.


The only way I can think of is to assign unique IDs to each objects and 
store these IDs to file.
When these objects are later restored, I used these IDs find the actual 
objects and re-assign them back to the object references.


It is tedious. Is there a smarter way?

Also, there are some TNotifyEvent fields  e.g. OnClick, OnClose etc.  
How do I save and restore them from file?


Many thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] RunError(215) occurs only in win 64 bit, not win 32 bit

2018-01-24 Thread Dennis



Bart wrote:

On Wed, Jan 24, 2018 at 12:59 PM, Marco van de Voort  wrote:


Which seems correct. The expression to compare with is entirely longword and
it gets negative (5+5) - (10+10).

But shouldn't it then also give the same error if compiled for 32 bit?


Agree.

The weird thing is, in 32 bit, the compiler gives the  Hint: (4079) 
Converting the operands to "Int64" before doing the add could prevent 
overflow errors.

but does not raise the RunError(215).

The 64 bit compiler does not give the Hint but raises the RunError(215).

I think both versions should be fixed.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] RunError(215) occurs only in win 64 bit, not win 32 bit

2018-01-24 Thread Dennis
When I compiled the following simply programs using Lazarus 1.8  fpc 
3.0.4 Win 64, run it, it will throws RunError(215) Arithmetic overflow 
error.


However, if I compile and run the same in Lazarus 1.8 fpc 3.0.4 win 32, 
it won't raise the RunError (215).

Why???


program test64bit;
{$mode objfpc}{$H+}
{$OVERFLOWCHECKS ON}
var
  LW1, LW2 : array[false..true] of LongWord;
  c : currency;
  aBoolean : Boolean;
begin
  LW1[false] := 5;
  LW1[true] := 5;

  LW2[false] := 10;
  LW2[true] := 10;
  c := 10;
  aBoolean :=  (LW1[true] + LW1[false]) - (LW2[false]+LW2[true]) > c ;
  Writeln('if compiled in 64 bit, a RunError(215) will have occurred 
and it will not reach this line');

  readln;
end.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] can inherited simply replace inherited method(param1, param2, param3)?

2018-01-11 Thread Dennis

are the 2 below equivalent?

procedure Method(param1, param2 : integer);
begin
  inherited;
end;



procedure Method(param1, param2 : integer);
begin
  inherited Method(param1, param2);
 end;

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] any existing units/libraries for sorting?

2018-01-03 Thread Dennis Poon



Santiago A. wrote:

El 03/01/2018 a las 16:09, Dennis escribió:

I have a list of records (each with a few fields).

What do you mean with list?
A TList? You can use sort method


Thanks for the reminder. I forgot about it.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] any existing units/libraries for sorting?

2018-01-03 Thread Dennis

I have a list of records (each with a few fields).
I want to let users display this list of records in ascending orders of 
any record field.

Is there any existing units/library I can use?

Thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Why win64 program are considerably bigger in exe size than win 32?

2017-12-22 Thread Dennis

I am upgrading my program from win 32 to win 64 using the new Lazarus 1.8.
I discovered my program exe size increased from 6M to 9M.

Why?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Cannot find entry point of a routine inside a windows 64 dll

2017-12-17 Thread Dennis



Sven Barth via fpc-pascal wrote:

On 15.12.2017 16:10, Dennis wrote:

Okay, that explains things a bit more.

May I ask you to provide a small example consisting of program and
library (source only) that works in 32-bit, but fails in 64-bit? Try
way I can check myself what is going on as I have a Delphi starter on
my 64-bit Windows as well. Though it will be the weekend till I'll
have the time to look at it.

Sven,

Attached is a zipped file containing the Caller program and Callee dll.
Both Compiled ok in windows 32 but when running Caller.exe, it reported
the error.

Thanks a lot.

There were two adjustments I had to do to make it work correctly:

- add {$mode objfpc} to Caller.lpr as I was compiling from the commandline
- adjust the casing of ReOpenExcelWorkBook so that it matched the one
from ReopenExcelWorkBook (these are case sensitive!)

With these changes it worked without problem on win64.

That said you might want to apply the following two points to your
library interface:
- export/import functions/procedures using explicit names (extending
"external LibName" to "external LibName name 'ProcName'" for each
routine to import and adding "name 'ProcName'" for each routine in the
exports section) to be sure that no name mangling interferes here
- add an explicit calling convention to each routine for import and
export (you could use "register", the default calling convention since
Delphi and FPC *should* be compatible here, but "stdcall" would be my
suggestion to be on the save side)

Additionally you can check for any discrepancies using the Dependency
Walker ( http://www.dependencywalker.com/ ). Just open the executable
while the library is located in the same directory and you can see which
routines mismatch.

Regards,
Sven



Thank you so much!!!

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Cannot find entry point of a routine inside a windows 64 dll

2017-12-13 Thread Dennis



Sven Barth via fpc-pascal wrote:
Am 13.12.2017 11:39 schrieb "Dennis Poon" <mailto:den...@avidsoft.com.hk>>:




Just for clarification: is the excel_xp.dll written by you or by a 3rd 
party? Or are you talking about a different library written by you? 
Because in the latter case the interfacing choice between your program 
and *that* library nicht be the culprit.


Let me explain. My program is a 32 bit program that collects real time 
stock prices and group the prices by each minute into Open, High, Low, 
Close, Volume of that minute. The program needs to add these rows of 
open,high,lose,close,volume in real-time to an opened Excel Spreadsheet 
(that the end users will write his own VBA formula to manipulate the 
rows I add).  To do so, I need to use Microsoft OLE Automation but I 
don't know how to do it in Lazarus. But there is a component in Delphi 
that uses OLE Automation to update an excel spreadsheet, so I wrote my 
own excel_xp.dll in Delphi to use that TExcelApplication component (from 
Delphi) which is then called by my 32-bit lazarus program.  Everything 
worked in 32-bit.


Since there is no FREE 64-bit Delphi IDE available, before I purchase a 
64-Bit delphi, I need to make sure my Lazarus program can compile to 64 
bit windows program and can call a 64-bit windows DLL so I use Lazarus 
64 bit to write a stub 64-bit windows dll to be called by my 64-bit 
Lazarus program. However, on running, it complained "Cannot find entry 
point of a routine ", which never happened when everything was 32-bit.


My question is why the exact routine definitions worked in 32-bit but 
did not work in 64 bit.


Someone might asked why I did not compile the TExcelApplication directly 
in Lazarus to do without the linked dll. I tried, it just won't compile 
and the task of translating the huge source files from Delphi to FPC is 
too daunting.


Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Cannot find entry point of a routine inside a windows 64 dll

2017-12-13 Thread Dennis Poon



Sven Barth via fpc-pascal wrote:
Am 13.12.2017 03:04 schrieb "Dennis" <mailto:de...@avidsoft.com.hk>>:


I am converting my windows 32 program to 64 bit.
It compiled with lazarus without any problem.(fpc 3.0.2)

I also compile the dll that is used, into a 64 bit dll.

However, when I ran the 64 bit program, windows reported 'cannot
find the entry point "the routine name in the dll" (the dll file name)

In the routine of the dll, there is an out parameter of type
WideString,

could this be the problem?

If not, what else could be the cause of the problem?


Considering the code you gave I really wonder how that ever worked... 
Did you set the calling convention using the $calling directive? 
Otherwise you need to add it to every function. Also you're on the 
eager side by using the "name" clause for the external as you can be 
sure then what name is used. Lastly are you sure that the DLL you're 
dealing with is a 64-bit library?


In the original 32 bit program, I wrote the windows 32-bit dll in the 
Starter (FREE) edition of Delphi and call (using those codes I showed 
you) from my FPC 32 bit program without any problem.
Since there is NO FREE Delphi for 64 bit version, I wrote a windows 
64-bit program using FPC 64 bit and then try calling it from my FPC 
64-bit program and encountered the "Cannot find entry point of a routine 
inside a windows 64 dll" error.


In the 32 bit program, I did not use the $calling directive and did not 
use 'name' clause and it worked perfectly.
I could add the name clause in the 64 bit program, but can you teach me 
how to use the $calling directive?
Since in the 64 bit version, i will be writing both the dll and the 
calling program, what $calling directive should I use?

Do I need to specify it clearly on both the dll and the calling code?

Maybe you should take a look at fpSpreadsheet which allows you to work 
with Excel files of different versions directly and does not need a 
library.


I tried to use the fpSpreadsheet sample program last time. If the 64 bit 
dll thing did not work out, I will have to rely on the fpSpreadsheet 
thing but my customers are all used to Excel and prefer sticking to it :-(


Thanks for your response.

Dennis

Regards,
Sven


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Cannot find entry point of a routine inside a windows 64 dll

2017-12-12 Thread Dennis

I am converting my windows 32 program to 64 bit.
It compiled with lazarus without any problem.(fpc 3.0.2)

I also compile the dll that is used, into a 64 bit dll.

However, when I ran the 64 bit program, windows reported 'cannot find 
the entry point "the routine name in the dll" (the dll file name)


In the routine of the dll, there is an out parameter of type WideString,

could this be the problem?

If not, what else could be the cause of the problem?

Below is the calling program:
Dennis

-

const
  ExcelDLLName = 'Excel_xp.dll';//1.90951
Type
   TFileNameString = WideString;//1.90951
   TExcelErrorString = WideString;//1.90952
   TExcelValueString = WideString;//1.90952



   EExcel_OLE=class(Exception);
   EExcel_OLE_Rejected=class(EExcel_OLE);
   EExcel_OLE_Rejected_ToWrite = class(EExcel_OLE_Rejected);

 procedure Excel_Finalize;external ExcelDLLName name 'Finalize';
procedure ResetExcelOLE(out TheError: TExcelErrorString);external 
ExcelDLLName;//1.90967


//1.90952 function OpenWorkBook(TheFileName : TFileNameString; out 
TheErrorIdx : integer) : integer;external ExcelDLLName;
//1.90952 function OpenWorkSheet(const TheWorkBook : integer; const 
TheSheetName : TFileNameString; out TheErrorIdx : integer) : 
integer;external ExcelDLLName;


//1.90952  procedure WriteToCell(const TheWorkSheet : integer; const 
TheRow, TheCol : integer; TheValue : String);external ExcelDLLName;
//1.90952 function WriteToRange(const TheSheetIndex : integer;TheRow, 
StartCol: integer; TheValues: array of variant; IsSkipIfNoChange: 
Boolean ) : integer;external ExcelDLLName;//used internally
procedure WriteToExcelRow(const TheSheetIndex: integer; TheRow, 
StartCol: integer; TheValues: array of Variant; out TheError: 
TExcelErrorString);external ExcelDLLName;//used internally


procedure WriteRow(const TheSheetIndex : integer;TheRow, StartCol: 
integer; TheValues: array of variant; var TheError : 
TExcelErrorString);external ExcelDLLName;//used internally
//1.90952 function GetCellValue(const TheWorkSheetIndex : integer; const 
TheRow, TheCol : integer) : Variant;external ExcelDLLName;



function GetCellVariant(const TheWorkSheetIndex : integer; const TheRow, 
TheCol : integer; var TheError : TExcelErrorString) : Variant;external 
ExcelDLLName;


function  IsRangeNull(const TheSheetIndex : integer;const TheRow, 
StartCol, TheRowCount, TheColCount : integer; var TheError : 
TExcelErrorString) : Boolean;external ExcelDLLName;



function GetExcelRange(const TheWorkSheetIndex: integer; const TheRow, 
TheCol, TheRowCount, TheColCount: integer; var TheError: 
TExcelErrorString): variant; external ExcelDLLName;


function OpenExcelWorkBook(TheFileName: TFileNameString; out TheError: 
TExcelErrorString): integer;external ExcelDLLName;
function OpenExcelWorkSheet(const TheWorkBook: integer; const 
TheSheetName: TFileNameString; out TheError: TExcelErrorString): 
integer;external ExcelDLLName;
procedure WriteToExcelRange(const TheSheetIndex: integer; TheRow, 
StartCol: integer; TheValues: Variant; out TheError: 
TExcelErrorString);external ExcelDLLName;


procedure ReOpenExcelWorkSheet(TheWorkSheetIndex : integer; out TheError 
: TExcelErrorString);external ExcelDLLName;//1.90966
procedure ReOpenExcelWorkBook(TheWorkBookIndex : integer; out TheError : 
TExcelErrorString);external ExcelDLLName;//1.90966
procedure SaveAllExcelWorkBooks(out TheError : 
TExcelErrorString);external ExcelDLLName;//1.90967
procedure SaveExcelWorkBook(TheBookIndex : integer; out TheError: 
TExcelErrorString);external ExcelDLLName;//1.91495


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Is there any pascal interface to TensorFlow or other neural network tools?

2017-12-07 Thread Dennis Poon



schuler wrote:

"> or even neural network libraries written in Pascal?
Try contacting schuler in Lazarus forum. "

Hello, this is schuler!!!

You can find the most recent project update here:
https://forum.lazarus.freepascal.org/index.php/topic,39049.0.html

There are many neural network layers (convolution, maxpool, concat, full
connect, local connect, ...) on 1D, 2D and 3D plus initialization functions
(uniform, Glorot, He, LeCun). Although the OpenCL implementation is still
cooking, the AVX implementation rocks.




Thanks.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Lazarus Release 1.8

2017-12-07 Thread Dennis



Mattias Gaertner wrote:


The Lazarus team is glad to announce the release of Lazarus 1.8.

The release was built with FPC 3.0.4.
The previous release Lazarus 1.6.4 was built with FPC 3.0.2.


Congratulations and thank you for your great work.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Is there any pascal interface to TensorFlow or other neural network tools?

2017-10-28 Thread Dennis Poon



Michael Van Canneyt wrote:



On Sat, 28 Oct 2017, Dennis wrote:


or even neural network libraries written in Pascal?

I know there are many python interfaces/libraries but I hope to use 
Pascal entirely so that I don't have to run a python server along 
side my Free Pascal program.


Or, is it possible to call python from Free pascal?

If not, in the worst case, I have to write  python tcp/ip server to 
accepts commands from (and send back results to ) my FPC program.


Tensorflow has a C library interface, the c_api.h header can be easily
translated with h2pas.

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/c/c_api.h

I did a quick run, it translates quite well.

Michael.


That's good news. Thanks a lot.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Is there any pascal interface to TensorFlow or other neural network tools?

2017-10-28 Thread Dennis

or even neural network libraries written in Pascal?

I know there are many python interfaces/libraries but I hope to use 
Pascal entirely so that I don't have to run a python server along side 
my Free Pascal program.


Or, is it possible to call python from Free pascal?

If not, in the worst case, I have to write  python tcp/ip server to 
accepts commands from (and send back results to ) my FPC program.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] how to get a list of all thread id

2017-10-05 Thread Dennis
In my multi thread programs (I use multiple threads in my program and 
the windows dll that I used also used multiple threads), from time to 
time, there are some problems (e.g some exceptions are raised) which 
caused my program to free after the Application.Run.


The freezing seem to occur even after the finalization of units.

From the task manager, I can see that there are 2 running threads in my 
program (down from a dozen when the program was running ).


Using the gdb does not help me pin point which thread is running wild 
causing the freezing.


I am wonder if I can list out all running thread ids after 
Application.Run, I might find out what those 2 threads are.


Can I do that in windows 32-bit?
Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How to call C++ function with Vector

2017-09-26 Thread Dennis Poon



Marco van de Voort wrote:


I myself generally solve this with a wrapper DLL, by crafting a DLL in C++
that exports a C (not C++) interface, and then use that. The same method as
QT is used from Lazarus (via wrapper dll/.so qtpas)
___

Thanks.  I think I will follow your advice.

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] How to call C++ function with Vector

2017-09-26 Thread Dennis

I have a windows 32-bit dll written in C++ (probably C++ Builder).
It has 1 function which I need to call:

int SPAPI_GetProduct(vector& apiProdList)

I am stuck at the keyword vector.

How is it translated into free pascal?

Is the following correct?

type
   TSPApiProduct_Array = array of SPApiProduct;

function SPAPI_GetProduct(var apiProdList : TSPApiProduct);stdcall;

Thanks a lot in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Is it always safe to typecast a old style object as its parent?

2017-08-01 Thread Dennis



TParent = object
   A : integer;
end;

TChild=object(TParent)
   B : integer;
end;


var
   Parent : TParent;
   Child : TChild;


 begin

Child.A := 10;
Child.B := 20;

Parent := TParent(Child );//  is this always safe ? Will it copy 
ONLY the 'A'  field to 'parent'?  Will it overwrite some memory space 
beyond the legitimate boundary of 'parent'?


end.


Thanks a lot in advance.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] why the 0.5 in the Unix Epoch (for UnixToDateTime function)

2017-08-01 Thread Dennis Poon



Vojtěch Čihák wrote:


Hi,

wiki https://en.wikipedia.org/wiki/Julian_day says that "... Julian 
day number 0 assigned to the day starting at noon on January 1, 4713 
BC, ..."


The noon means 0,5.


Thanks,
that is a weird definition though IMHO.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] why the 0.5 in the Unix Epoch (for UnixToDateTime function)

2017-08-01 Thread Dennis

I just noticed that the definition of the constants have 0.5 in it.
Why?


from dateh.inc
const
   JulianEpoch = TDateTime(-2415018.5);

   UnixEpoch = JulianEpoch + TDateTime(2440587.5);


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Why casting interface as Tobject will result in a different reference?

2017-05-27 Thread Dennis Poon



Sven Barth via fpc-pascal wrote:

The idea itself is valid, cause "(IMyInterfaceVar as TObject) as
IMyInterface = IMyInterfaceVar" is true if and only if IMyInterface is
a COM interface. If IMyInterface really is a CORBA interface as Dennis
wrote then the compiler should already have complained at the "aObj :=
aInt as TObject" line as this type of conversion is*not*  supported by
CORBA interfaces (cause they don't provide QueryInterface() which is
needed for this). At least for me the compiler*did*  complain (both
3.0.2 and 3.1.1) when I tested this.
So the question is: is IMyInterface indeed a CORBA interface? If so
then why does the compiler not complain? If not then why doesn't it
work? For both cases a full example would be needed to investigate
this.

Regards,
Sven

Sorry, I got it wrong. The interface was in fact COM style instead of CORBA.

In case of COM interface, why

var
   aInt : IMyInterface;
  aObj : TObject;
begin


...
   aInt := MyList.Items[0];

   aObj := aInt as TObject;

why sometimes (not always)   aInt  <>   (aObj as IMyInterface ) ?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Why casting interface as Tobject will result in a different reference?

2017-05-26 Thread Dennis

I defined a generic TList //CORBA style interface

var
   aInt : IMyInterface;
  aObj : TObject;
begin
   aInt :=  MyList.Items[0];
   aObj := aInt as TObject;

  writeln(  IntToHex(LongWord(aInt),4));

  writeln(  IntToHex(LongWord(aObj),4)); //this will output a different 
Hex value from previous writeln



//This is causing a problem to me because I later

  MyList.Remove(aObj as IMyInterface);//will fail because it is not the 
same as aInt and thus fail to locate the item to remove



Am I missing some fundamental understanding of interface reference?

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] GUI multithreaded Win32 program sometimes freeze when quitting

2017-04-18 Thread Dennis

I have an win32 multithreaded program written in lazarus 1.7, FPC 3.1.1

From time to time, when it quits, it will freezes and from the task 
manager, the program will occupies the entire CPU core.


I noticed that it will happen more often if:
1)
constructor TMyComponent.Create(TheOwner : TComponent);
begin

   self.some_component := TSomeComponent.Create(TheOwner);
end;


instead of

constructor TMyComponent.Create(TheOwner : TComponent);
begin

   self.some_component := TSomeComponent.Create(self);
end;


2) if the program executes some methods of a nil object



3) if I don't do a build all when some common units are changed by 
another project.




Since this freezing behavour does not happen during debugging, I have 
spent months trying to fix it but failed.


Any suggestions are welcome.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] how to determine if a class has descendant registered within the current program

2017-03-08 Thread Dennis
I have a many classes, one inherits from another one, in an ancestor 
method, I want to test whether the calling class is a childless class.


e.g.
class function TAncestor.GetCaption : String; //virtual
begin
if HasChild then
  result := 'something'
  else
result := 'something else';

end;


where HasChild is a boolean class function that tells me whether the 
current calling class has children defined or now.


Is that possible?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Run Time Type Info - are the type names of all classes defined in a unit stored in the RTTI?

2017-03-01 Thread Dennis Poon



Sven Barth wrote:


Am 01.03.2017 11:53 schrieb "Dennis" <mailto:de...@avidsoft.com.hk>>:

>
> Programmatically, I want to make a list of all Classes defined in 
the unit.

> Is this info stored in the RTTI or anywhere else?

This info is not yet available, but will be in the future.



Thanks.

Ideally, with this feature, in the initialization section of the unit, I 
can 'register' all the classes defined in the unit into a 
dictionary.
That way, when loading objects from file, I can use the dictionary to 
lookup the actual TClass with the stored Classname, to recreate the 
object stored.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] Run Time Type Info - are the type names of all classes defined in a unit stored in the RTTI?

2017-03-01 Thread Dennis

Programmatically, I want to make a list of all Classes defined in the unit.
Is this info stored in the RTTI or anywhere else?

Thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] how to use Default to replace this ' FillChar(aRecord, sizeof(aRecord), 0);

2016-12-05 Thread Dennis Poon



Lars wrote:

Do you know about this feature:

var
   SomeRec: TSomeRecord = ();

This is good for global variable.
But I wonder whether it has effect in procedure's local variable since 
it requires the compiler to clear the record on the stack (which is at 
different location every time).


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] how to use Default to replace this " FillChar(aRecord, sizeof(aRecord), 0);

2016-12-05 Thread Dennis Poon



Sven Barth wrote:


Am 05.12.2016 08:24 schrieb "Dennis" <mailto:de...@avidsoft.com.hk>>:

>
> In this old statement, I don't need to know the type of aRecord
> but if I want to use Default, I have to know the exact type of the 
varaible aRecord and pass it to Default(aRecordType) e.g. aRecord := 
Default(aRecordType)  //where var  aRecord : aRecordType

>
> Is it possible to use default without knowing the variable type? (it 
is because sometimes the type get renamed)


No, it's not possible. You'll simply have to rename one more location.

Regards,
Sven



Thanks.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] how to use Default to replace this " FillChar(aRecord, sizeof(aRecord), 0);

2016-12-04 Thread Dennis

In this old statement, I don't need to know the type of aRecord
but if I want to use Default, I have to know the exact type of the 
varaible aRecord and pass it to Default(aRecordType) e.g. aRecord := 
Default(aRecordType)  //where var  aRecord : aRecordType


Is it possible to use default without knowing the variable type? (it is 
because sometimes the type get renamed)


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] can a class implement both a CORBA interface and an COM interface at the same time?

2016-11-17 Thread Dennis



Dennis wrote:

I have a class implementing a Com interface.
Now I want it to also implement a CORBA interface. Is it dangerous?


For other who might be interested in this issue.
I have tested it for a while and it does not seem to cause any problems.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] can a class implement both a CORBA interface and an COM interface at the same time?

2016-11-16 Thread Dennis

I have a class implementing a Com interface.
Now I want it to also implement a CORBA interface. Is it dangerous?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] TMS Aurelius Free today

2016-11-10 Thread Dennis

From Facebook, I just found this ORM became FREE today.

http://www.tmssoftware.com/site/aureliusfree.asp

I don't know whether it is better than mormot but might just download first.

Anyone has experience in both can comment?

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Does FPC has anything like TCriticalSection.Acquire with timeout?

2016-11-02 Thread Dennis
If a CriticalSection can acquire (but with a timeout), it can avoid any 
gridlock.


I googled and Delphi seems to have function which does time out

function  MonitorEnter(const  AObject:  TObject;  Timeout:  Cardinal  =  
INFINITE):  Boolean; How can I do the same in FPC? Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] what is the possible cause of EPrivilege Privileged instruction ?

2016-10-26 Thread Dennis Poon



Snorkl e wrote:


Your not using teventobject in your threads are you?
There is a bug in the RTL which could cause weird issues with threads 
if you are using teventobject.create.




I don't use TEventObject (because I don't know how to use it).
I have my internal task queue that my worker thread loop through the 
task queue.

The exception was raised within one of the many tasks in the task queue.

Dennis
On Oct 26, 2016 10:58 AM, "Dennis" <mailto:de...@avidsoft.com.hk>> wrote:


I have a multi threaded program which executes a list of tasks in
real time.
It is difficult to debug with a debugger on this program (since
debugging will pause the execution which will be messy for this
application).

So, I log the exceptions to a log file and I found this exception:
EPrivilegePrivileged instruction

What could possibly raise this exception?

My program is win 32 from Lazarus 1.7  FPC 3.1.1
and running on Win 7 64 bit.

thanks in advance.

Dennis
___
fpc-pascal maillist  - fpc-pascal@lists.freepascal.org
<mailto:fpc-pascal@lists.freepascal.org>
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
<http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>



___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] what is the possible cause of EPrivilege Privileged instruction ?

2016-10-26 Thread Dennis

I have a multi threaded program which executes a list of tasks in real time.
It is difficult to debug with a debugger on this program (since 
debugging will pause the execution which will be messy for this 
application).


So, I log the exceptions to a log file and I found this exception:
EPrivilegePrivileged instruction

What could possibly raise this exception?

My program is win 32 from Lazarus 1.7  FPC 3.1.1
and running on Win 7 64 bit.

thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Free Delphi 10.1 Berlin Starter Edition

2016-08-23 Thread Dennis



wkitt...@windstream.net wrote:

On 08/23/2016 11:40 AM, Dennis wrote:

Thanks a lot.
I wonder if there is any catch.


you mean like having to create an account, having to provide a phone 
number or having to run it in a winwhatever environment? ;)

\

it says:
"a limited commercial use license"

I wonder that means.

To me, the company has a very bad public image after Delphi 7, so I get 
paranoid.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Free Delphi 10.1 Berlin Starter Edition

2016-08-23 Thread Dennis



Maciej Izak wrote:

Hi,

finally we have simple way to test new syntax to improve FPC quality / 
$MODE DELPHI without spending $ on Delphi :)


Probably limited time offer:

https://www.embarcadero.com/products/delphi/starter/promotional-download

--
Best regards,
Maciej Izak


Thanks a lot.
I wonder if there is any catch.
Anyway, I gave up Delphi after Delphi 5 and stick to FPC since then.  
However, from time to time, I miss its lightning fast compiler and good 
debugger.


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Resource strings, passwords etc.

2016-07-13 Thread Dennis Poon



Graeme Geldenhuys wrote:

On 2016-07-13 08:31, Mark Morgan Lloyd wrote:

Sometimes it's difficult to avoid having to do that sort of thing, or
obfuscating them in an external file.

You could use something like DCPCrypt to help the cause. Or you could
follow similar tactics to what OnGuard uses - encode sensitive text in a
data structure. At the very least use a const of bytes instead of clear
text. For example:



May I know what OnGuard is? googling it returns something irrelevant.

On the subject,  can the OP simply use UPX to encrypt the executable 
binary. It won't be secured but no more unsecured than other simple 
solutions.


UPX is at http://portableapps.com/apps/utilities/free_upx_portable

The original sourceforge.net link is dead, I don't know why.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Surprise. Comparison of method is only done on the routine address

2016-07-12 Thread Dennis Poon



Michael Van Canneyt wrote:



On Tue, 12 Jul 2016, Dennis wrote:

I always thought comparison of methods is done on both the data and 
the code part.

  TMethod = record
Code : CodePointer;
Data : Pointer;
  end;
But the following proves it is NOT.
What is the rationale behind such behavior?


AFAIK: Delphi compatibility.


May I know what do they claim to be the rationale behind this decision?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Surprise. Comparison of method is only done on the routine address

2016-07-11 Thread Dennis
I always thought comparison of methods is done on both the data and the 
code part.

   TMethod = record
 Code : CodePointer;
 Data : Pointer;
   end;
But the following proves it is NOT.
What is the rationale behind such behavior?

--
program compare_events;
{$mode objfpc}{$H+}
uses classes;
type

  TA=class
procedure Proc(aSender : TObject);virtual;
  end;

  TB=class(TA)
procedure Proc(aSender : TObject);override;
  end;

  TC=Class(TA)
  end;

var
  E1,E2,E3 : TNotifyEvent;
  A : TA;
  B : TB;
  C : TC;
procedure TB.Proc(aSender: TObject);
begin
  inherited Proc(aSender);
end;

procedure TA.Proc(aSender: TObject);
begin

end;

begin
  a := TA.Create;
  B := TB.Create;
  C := TC.Create;
  try
E1 := @(A.Proc);
E2 := @(B.Proc);
E3 := @(C.Proc);
if E1 = E2 then
  Writeln('A.Proc = B.Proc')
else
  Writeln('A.Proc <> B.Proc');

if E1 = E3 then
  Writeln('A.Proc = C.Proc')
else
  Writeln('A.Proc <> C.Proc') ;

Readln;
  finally
A.Free;
B.Free;
C.Free;
  end;
end.

{===the program gives the following output}

A.Proc <> B.Proc
A.Proc = C.Proc
{end of output}





___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] can the compiler zero any out parameter of procedure/function automatically?

2016-07-11 Thread Dennis Poon



Jonas Maebe wrote:

Dennis wrote:

I know it is my responsibility to initialize out parameters, but I think
the compiler could help us by initializing all out parameters.

The compiler will fill out-parameters with garbage if you use the -gt
command line parameter, which can help you detect such problems more easily.

If you forget to assign a value to an out-parameter in a particular
case, having it return nil by default could easily be just as wrong as
it returning any other random value. For that reason, there is no
support for automatically initialising out-parameters.


How about issue a compiler warning if one forgets to zero any out parameter?

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] can the compiler zero any out parameter of procedure/function automatically?

2016-07-11 Thread Dennis
I just found the cause of a strange bug is because I forgot to zero the 
out parameter of a procedure like.


procedure FindEvent (out TheEvent : TNotifyEvent);
begin
  TheEvent := nil;//I forgot to add this line before all the 
processing, which sometimes did not assign to TheEvent at all

    long code...
end;


when later, I called.
var
  aEvent : TNotifyEvent;
 FindEvent(aEvent);
  if assigned(aEvent) then
   aEvent(nil);  -> cause serious error that crash the program.


I know it is my responsibility to initialize out parameters, but I think 
the compiler could help us by initializing all out parameters.

Am I the only one with this view?

Dennis


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] what is the correct way to write {$IFDEF FPC Version > 3.0}

2016-07-08 Thread Dennis Poon



Bart wrote:

On 7/8/16, Dennis  wrote:


what is the correct way to write {$IFDEF FPC Version > 3.0}

See answers above.

For your information:
FPC_FULLVERSION construction:
Major*1 + Minor*100 + Revision

Thank you all for your answers.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] what is the correct way to write {$IFDEF FPC Version > 3.0}

2016-07-08 Thread Dennis

what is the correct way to write {$IFDEF FPC Version > 3.0}

Thanks in advance,

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Is there a reactive framework for Free Pascal?

2016-07-07 Thread Dennis Poon



Sven Barth wrote:


Am 07.07.2016 10:13 schrieb "Graeme Geldenhuys" 
mailto:mailingli...@geldenhuys.co.uk>>:

>
> Hi Dennis,
>
> Would you mind explaining what is a “reactive framework”?

http://reactivex.io/

Once we support helpers for interfaces and anonymous functions (and 
maybe lambda expressions ^.^ ) one could try to port it.


Regards,
Sven


How about for the time being, any library to help with distributing 
tasks to various threads' queue.
Right now, only Application.QueueAsycnCall has a queue to which you can 
send tasks (  procedure (integer) of object ).

Normal Tthread has  no queues.
I am implementing my own queues for worker thread and encounter some 
problems when the program quits and some objects not being freed at the 
right order.
The application then just hangs (I suppose because some objects are 
still not freed so UI thread keeps on waiting). One of the 4 CPU cores 
is thus at full capacity for ever.


I hope someone has done some work in this area which I can learn from.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Is there a reactive framework for Free Pascal?

2016-07-05 Thread Dennis


Is there something like Rx.net for Free Pascal?

Dennis

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] What is the difference between TThread.Queue(aMethod: TThreadMethod) and Application.QueueAsyncCall(AMethod: TDataEvent; Data: PtrInt);

2016-07-01 Thread Dennis

Apart from the TThreadMethod and TDataEvent, what are the major differences?
Are both of them thread safe to call from non-main thread?
Will both of them overwrite some queue or buffer if the queues are full?

I tried to study the source code but I cannot find the implementation parts.
I only find the interface parts of TThread classesh.inc

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Bls: Bls: Quick Modern Object Pascal Introduction, for Programmers

2016-06-22 Thread Dennis Poon
I saw your document on for x in ListX  loop and would like to reconfirm 
that it is always iterated in ascending order, right?


can we do it in descending order without a user defined enumerator? i.e. 
for simple enumerated type, is there a construct to iterate through it 
in descending order?


Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] why (ClassType as TMyClass).Create fails

2016-06-21 Thread Dennis

Following up to the cloning example code:

Type
 TMyClassRef = class of TMyClass;

implementation

function TMyClass.Clone(AOwner: TComponent): TMyClass;
begin
  Result := TMyClassRef(ClassType).Create(AOwner);

//but the next line will fail to compile
//  Result := (ClassType as TMyClassRef).Create(aOwner);
  Result.Assign(Self);
end

Isn't (ClassType as TMyClassRef).Create(aOwner)  supposed to be safer 
because sometimes we copy and paste code around and in the end  
(ClassType might not be a descendant of TMyClass and the compiler won't 
catch this type mismatch if we do


  Result := TMyClassRef(ClassType).Create(AOwner);

Am I missing something?

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Quick Modern Object Pascal Introduction, for Programmers

2016-06-21 Thread Dennis Poon



2) use of ClassType function for cloning objects

I added two things:

- A section about TPersistent.Assign. This is the "basic approach to
cloning" that should probably be shown first. See it here:
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_cloning_tpersistent_assign
. I mentioned the special rules when calling the "inherited" from
Assign overrides, and AssignTo, and the fact that TPersistent makes
the default visibility "published".

- And the ClassType, with the example of Clone method using it, is
added at the desciption of "class references" on
http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_class_references


Just read your example

|function TMyClass.Clone(AOwner: TComponent): TMyClass; begin // This 
would always create an instance of exactly TMyClass: //Result := 
TMyClass.Create(AOwner); // This can potentially create an instance of 
TMyClass descendant: Result := TMyClassRef(ClassType).Create(AOwner); 
Result.Assign(Self); end |


|I remember someone once asked whether we should override the method 
Assign or AssignTo.|
|I am worried, choosing the wrong method to override will produce 
unexpected result.|

||
|Dennis|

||
|
|

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] What is the difference between case else and case otherwise

2016-06-20 Thread Dennis

There is no details on http://www.freepascal.org/docs-html/ref/refsu57.html

Thanks in advance.

Dennis
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


  1   2   3   >