[fpc-pascal] Is there any benefit for a Delphi/Free Pascal/Lazarus programmer to build a C DLL in debug mode ?

2022-08-30 Thread Skybuck Flying via fpc-pascal
Is there any benefit for a Delphi or Free Pascal/Lazarus programmer to build a 
C DLL in debug mode ?

Could it and would it somehow lead to better debugging ?
If so how ? So far I don't notice any difference between debug or release build 
from within Delphi.

Maybe Release/Debug in this case/context only matters for those trying to debug 
the C DLL from inside Visual Studio ?!? Like attach to executable ? Or run with 
host application executable ? Such a feature... ?

Building Uber H3 Library can be done as follows:

Step 1: Use CMakeGUI to make build folder
Step 1.1: Select source folder, example:
E:\SourceCode\H3V4\

Step 1.2: Select build folder, example:
E:\SourceCode\H3V4-build\

Execute step 2 and step 3 in ms-dos command prompt from visual studio with 
special environment settings:

Step 2: Configure for DLL release:

cd E:\SourceCode\H3V4\
cmake "..\h3V4-build" -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON 
-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON

Step 3.1: Build release DLL

cd E:\SourceCode\H3V4-build\
cmake --build . --config Release

or

Step 3.2: Build debug DLL

cd E:\SourceCode\H3V4-build\
cmake --build . --config Debug

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


[fpc-pascal] Union field after property violates "field before property" rule + property of union field not possible.

2022-08-15 Thread Skybuck Flying via fpc-pascal
Delphi and presumably Free Pascal has some language inconsistency and 
problem/short coming concerning "Union Field" and/or "Union Property":

The (previous) presented solution (included at end of post) is inconsistent in 
two ways:

1. Property of union not possible.

2. Order of field and property violations "field before property" rule.

(Both problems demonstrated in TDataExample3)

{

version 0.03 created on 14 august 2022 by Skybuck Flying:

Today I remember the rule which this union field is conflicting with.

The rule: "field before property"

Going to demonstrate it below

There are apperently two problems with this solution:

1. Property of union not possible ?!?

2. Inconsistent language design in respect to standard field + property relation
(order of appearance/declaration)

// ERROR "field definition not allowed after methods or properties" problem 2.

}


type
  TDataExample3 = record

//  mStandardField : integer;  // OK

// normal/standard property
property StandardField : integer read mStandardField write 
mStandardField;

mStandardField : integer;  // ERROR "field definition not allowed 
after methods or properties" problem 2.


// union property
//  property UnionField : int64 read mData write mData;  // not 
possible, problem 1

// union fields
case integer of   // INCONSISTENT problem 2
  0 : ( mData : int64 );
  1 : ( mByte : packed array[0..7] of byte );

//  property UnionField : int64 read mData write mData;  // not 
possible, problem 1

  end;


The original problem was:

(*
  // ORIGINAL PROBLEM:
  TDataExample0 = record
  private
mField : integer;
  public
// UNION example
case integer of
  0 : ( mData : int64 );
  1 : ( mByte : packed array[0..7] of byte );

property Field read mField write mField; // DOES NOT COMPILE.
  end;
*)

  // UNION DECLARATION example that does work without properties, just to 
check"

  TDataExample1 = record
  private
mField : integer;

  public
// UNION example
case integer of
  0 : ( mData : int64 );
  1 : ( mByte : packed array[0..7] of byte );

// DOES COMPILE
  end;

Presented solution for union field in record with properties was:

  TDataExample2 = record
  private
mField : integer;

  public
// SOLUTION:
property Field : integer read mField write mField;

// PUT CASE STATEMENT LAST
case integer of
  0 : ( mData : int64 );
  1 : ( mByte : packed array[0..7] of byte );

  end;

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


[fpc-pascal] Union followed by Property does not compile !

2022-08-02 Thread Skybuck Flying via fpc-pascal
program TestProgram3;

{

Test program to illustrate the 'union' followed by property problem in Delphi
language and Free Pascal Language

version 0.01 created on 1 august 2022 by Skybuck Flying

There is a problem with "unions" in Delphi language:

When a property follows a "union" declaration it does not compile !

See
TDataExample1 which does compile (no property)
vs
TDataExample2 which does NOT compile (with property)

}

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  Classes, SysUtils, CustApp
  { you can add units after this };

type

  { TMyApplication }

  TMyApplication = class(TCustomApplication)
  protected
procedure DoRun; override;
  public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
  end;

{ TMyApplication }

type
  TDataExample1 = record
mField : integer;

// UNION example
case integer of
  0 : ( mData : int64 );
  1 : ( mByte : packed array[0..7] of byte );

// DOES COMPILE
  end;

  TDataExample2 = record
    mField : integer;


// UNION example
case integer of
  0 : ( mData : int64 );
  1 : ( mByte : packed array[0..7] of byte );

// !!! DOES NOT COMPILE, PROBLEM !!!
property Field : integer read mField write mField;
  end;

procedure TMyApplication.DoRun;
var
  ErrorMsg: String;
begin
  // quick check parameters
  ErrorMsg:=CheckOptions('h', 'help');
  if ErrorMsg<>'' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
  end;

  // parse parameters
  if HasOption('h', 'help') then begin
WriteHelp;
Terminate;
Exit;
  end;

  { add your program here }

  // stop program loop
  Terminate;
end;

constructor TMyApplication.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;

destructor TMyApplication.Destroy;
begin
  inherited Destroy;
end;

procedure TMyApplication.WriteHelp;
begin
  { add your help code here }
  writeln('Usage: ', ExeName, ' -h');
end;

var
  Application: TMyApplication;
begin
  Application:=TMyApplication.Create(nil);
  Application.Title:='My Application';
  Application.Run;
  Application.Free;
end.

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


[fpc-pascal] UBER H3 API working/partially converted

2022-08-01 Thread Skybuck Flying via fpc-pascal
(I mainly write this second e-mail to prevent you from wasting time on the 
previous e-mail, cause the conversion was already quite successfull with a 
different tool, read below)

The in Delphi written tool CHET was used to convert the C api for UBER H3 
library.

https://github.com/neslib/Chet
[https://opengraph.githubassets.com/b39cf935c557cba4185d6776c2195f5790769b08f096256d01ca89b5ab57a40c/neslib/Chet]
GitHub - neslib/Chet: C Header Translator for 
Delphi
Chet - C Header Translator for Delphi. Chet is a .h-to-.pas translator powered 
by libclang for Delphi.. Features. Unlike some other header translators, Chet 
uses the Clang compiler to parse header files, resulting in more accurate 
translations that require fewer manual adjustments.
github.com


CHET uses LIBClang for Delphi. Which can be found at: 
https://github.com/neslib/Neslib.Clang
[https://opengraph.githubassets.com/fc65d8cd6fa05f844e7d52fe10a26ddaa1814241a437d1e8c101db34bce19f7b/neslib/Neslib.Clang]
GitHub - neslib/Neslib.Clang: libclang for 
Delphi
Neslib.Clang - libclang for Delphi. Libclang is the C Interface to Clang's C 
family of compilers. It provides a relatively small API that exposes facilities 
for parsing source code into an abstract syntax tree (AST), loading 
already-parsed ASTs, traversing the AST, associating physical source locations 
with elements within the AST, and other facilities that support Clang-based 
development tools.
github.com


I don't know if LIBClang for Free Pascal Exist.

But this chet tool in combination with this LibClang was pretty awesome !

Especially cause this was quite a complex/bitch of an api, with crazy painfull 
macros, but the tool performed pretty well and did it's best and produced 
something useable.
I had to only disable/comments 5 lines of code.

The api was briefly tested and it seems to work !

Some improvements can be made by using properties to access H3Indexes directly 
etc.

This will be done/attempted in the near future.

For now for what it's worth here is the unit code, ofcourse it kinda sucks to 
have it in e-mail format.

Maybe later I uploaded it somewhere...

unit UBER_H3_API;
{ This unit is automatically generated by Chet:
  https://github.com/neslib/Chet }

{$MINENUMSIZE 4}

interface

const
  {$IF Defined(WIN64)}
  UBER_H3 = 'h3_release_64_bit.dll';
  _PU = '';
  {$ELSE}
{$MESSAGE Error 'Unsupported platform'}
  {$ENDIF}

const
  M_PI = 3.14159265358979323846;
  M_PI_2 = 1.5707963267948966;
  M_2PI = 6.28318530717958647692528676655900576839433;
  M_PI_180 = 0.017453292519943295769236907684886127;
  M_180_PI = 57.29577951308232087679815481410517033240547;
  EPSILON = 0.0001;
  M_SQRT3_2 = 0.8660254037844386467637231707529361834714;
  M_SIN60 = M_SQRT3_2;
  M_AP7_ROT_RADS = 0.333473172251832115336090755351601070065900389;
  M_SIN_AP7_ROT = 0.3273268353539885718950318;
  M_COS_AP7_ROT = 0.9449111825230680680167902;
  EARTH_RADIUS_KM = 6371.007180918475;
  RES0_U_GNOMONIC = 0.3819660112501053;
  MAX_H3_RES = 15;
  NUM_ICOSA_FACES = 20;
  NUM_BASE_CELLS = 122;
  NUM_HEX_VERTS = 6;
  NUM_PENT_VERTS = 5;
  NUM_PENTAGONS = 12;
  H3_CELL_MODE = 1;
  H3_DIRECTEDEDGE_MODE = 2;
  H3_EDGE_MODE = 3;
  H3_VERTEX_MODE = 4;
  { TODO : Unable to convert function-like macro: }
  (* H3_EXPORT ( name ) name *)
  H3_NULL = 0;
  H3_VERSION_MAJOR = 4;
  H3_VERSION_MINOR = 0;
  H3_VERSION_PATCH = 0;
  MAX_CELL_BNDRY_VERTS = 10;
  EPSILON_DEG = 0.1;
  EPSILON_RAD = (EPSILON_DEG*M_PI_180);
  NORMALIZATION_SUCCESS = 0;
  NORMALIZATION_ERR_MULTIPLE_POLYGONS = 1;
  NORMALIZATION_ERR_UNASSIGNED_HOLES = 2;
  { TODO : Macro probably uses invalid symbol "currentCoord": }
  (* INIT_ITERATION_LINKED_LOOP LinkedLatLng * currentCoord = NULL ; 
LinkedLatLng * nextCoord = NULL *)
  { TODO : Unable to convert function-like macro: }
  (* GET_NEXT_COORD ( loop , coordToCheck ) coordToCheck == NULL ? loop -> 
first : currentCoord -> next *)
  { TODO : Unable to convert function-like macro: }
  (* ITERATE_LINKED_LOOP ( loop , vertexA , vertexB ) currentCoord = 
GET_NEXT_COORD ( loop , currentCoord ) ; if ( currentCoord == NULL ) break ; 
vertexA = currentCoord -> vertex ; nextCoord = GET_NEXT_COORD ( loop , 
currentCoord -> next ) ; vertexB = nextCoord -> vertex *)
  { TODO : Unable to convert function-like macro: }
  (* IS_EMPTY_LINKED_LOOP ( loop ) loop -> first == NULL *)
  { TODO : Unable to convert function-like macro: }
  (* H3_MEMORY ( name ) name *)
  IJ = 1;
  KI = 2;
  JK = 3;
  INVALID_FACE = -1;
  INVALID_BASE_CELL = 127;
  MAX_FACE_COORD = 2;
  INVALID_ROTATIONS = -1;
  H3_NUM_BITS = 64;
  H3_MAX_OFFSET = 63;
  H3_MODE_OFFSET = 59;
  H3_BC_OFFSET = 45;
  H3_RES_OFFSET = 52;
  H3_RESERVED_OFFSET = 56;
  H3_PER_DIGIT_OFFSET = 3;
  { TODO : Macro probably uses invalid symbol "uint64_t": }
  (* H3_HIGH_BIT_MASK ( ( uint64_t ) ( 1 ) <<