Re: [fpc-pascal] Feature announcement: implicit generic function specializations

2022-04-22 Thread Howard Page-Clark via fpc-pascal

On 22/04/2022 17:13, Rainer Stratmann via fpc-pascal wrote:

Am Freitag, 22. April 2022, 17:27:33 CEST schrieb Hairy Pixels via fpc-pascal:

On Apr 22, 2022, at 8:48 PM, Rainer Stratmann via fpc-pascal

From assembly to high-level language there is a huge step.
 From high-level language to implicit generic function specializations it is a
little step regarding the benefits.

In my opinion it makes everything more complicated. My mind refuses to read
the description of the new feature.

But mostly I am worried because of the statement "has the potential to break
existing code".

Rainer,

We assume this is a language feature you will not use in your code, 
which is fine.


However, it is a cause for celebration among those who do welcome such 
syntax sugar, and will be using the feature to improve the size and 
readability of their code.


kind regards,

Howard

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


Re: [fpc-pascal] Improved FPC JSON-RPC support

2021-12-29 Thread Howard Page-Clark via fpc-pascal

On 29/12/2021 11:22, wkitty42--- via fpc-pascal wrote:

On 12/29/21 4:54 AM, Michael Van Canneyt via fpc-pascal wrote:
Translated to RPC: if you want speed, don't use HTTP or JSON. WST 
offers a

binary protocol and plain TCP channel, it's bound to be much faster.


i'm sorry... what is WST? googling for "wst binary protocol tcp ip 
channel" doesn't turn up anything informative for me and acronym 
searching is equally uninformative... getting old sucks :?



WST stands for Web Services Toolkit, a package that offers both 
provision (authoring) of web services, and facilitates programming web 
service consumption.


A package for the framework is available in Lazarus' online package manager.

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


Re: [fpc-pascal] TypeInfo on generic templates

2020-10-29 Thread Howard Page-Clark via fpc-pascal

On 29/10/2020 18:27, Ryan Joseph via fpc-pascal wrote:

Is it possible that the TypeInfo intrinsic could work with generic template types or is 
this a bug? I get "Illegal qualifier" in the procedure below.

generic procedure DoThis(a: array of T);
begin
   writeln(TypeInfo(T)^.name);
end;


Regards,
Ryan Joseph

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


What could .name return in this context?

"placeholder for an as-yet-unspecialised and unknown type"?

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


Re: [fpc-pascal] Enum range check error

2020-10-21 Thread Howard Page-Clark via fpc-pascal

On 21/10/2020 21:34, Ryan Joseph via fpc-pascal wrote:

I thought default would just return the first value in the enum but I guess 
it's just zeros. Maybe we need a better default for objfpc mode.
The first element is returned by Low(TEnum), and the first value by 
Ord(Low(TEnum)).


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


Re: [fpc-pascal] Dynamic Arrays in Procedures

2020-10-04 Thread Howard Page-Clark via fpc-pascal

On 04/10/2020 20:58, James Richters via fpc-pascal wrote:


I’m wondering if there is a way to pass an array of values to a 
Procedure without defining an array variable….


For example, if I have a Procedure:

Procedure DoSomething(X :Byte);

Then I can call it with a specific a variable like this:

Var

ThingA :Byte;

…

DoSomething(ThingA);

And I can also call it without a variable but instead just hard code a 
specific value like this:


DoSomething($1A);

So if I have a procedure like this:

Procedure DoSomethingElse(Y :Array of Byte);

I can call it like this:

Var

ThingB :Array Of Byte;

SetLength(ThingB,3);

ThingB[0] :=$12;

ThingB[1] :=$1A;

ThingB[2] :=$2B;

DoSomethingElse(ThingB);

But can I also just call it with specific values somehow?

DoSomethingElse([$12,$1A,$2B]);for example… of course this doesn’t 
work, but is there a syntax that would work?




There is array of const syntax.

== code==

program project1;

{$mode objfpc}

procedure ShowArray(anArray: array of const);
var
  i: Integer;
begin
  for i := Low(anArray) to High(anArray) do
    case anArray[i].VType of
  vtInteger: WriteLn(anArray[i].VInteger,' ');
  vtChar: WriteLn(anArray[i].VChar,' ');
    end;
end;

begin
  ShowArray([99, -1, 'p', 'G']);
  ReadLn;
end.

== code end==



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


Re: [fpc-pascal] Range check error warning.

2020-03-25 Thread Howard Page-Clark via fpc-pascal

On 25/03/2020 17:46, wkitt...@windstream.net wrote:

On 3/24/20 6:58 PM, Sven Barth via fpc-pascal wrote:

wkitt...@windstream.net schrieb am Di., 24. März 2020, 18:37:


you should figure out why typed constants are not being allowed/used
in your setup...


Typed constants can not be used to initialize constants.



hummm... ok, so how to you get a constant to be a byte and storing 7 
for the decimal value?


or are you saying that you cannot use a typed constant in the init of 
another (typed) constant



Try

const
  seven = Byte(7);

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


Re: [fpc-pascal] Pass open array to static array?

2020-03-15 Thread Howard Page-Clark via fpc-pascal

On 15/03/2020 12:06, Ryan Joseph via fpc-pascal wrote:

program test;
var
   data: array[0..2] of integer;
begin
   // Incompatible types: got "{Array Of Const/Constant Open} Array of ShortInt" expected 
"Array[0..2] Of LongInt"
   data := [1,2,3];
end.


With recent FPCs you can however do this:

program test;
var
  data: array[0..2] of Integer;
  tmp: array of Integer = Nil;
begin
  tmp := [1,2,3];
  Move(tmp[0], data[0], SizeOf(data));
end.


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


Re: [fpc-pascal] Compiler treatment of dotted reference in class property

2020-02-03 Thread Howard Page-Clark via fpc-pascal

On 03/02/2020 13:17, Sven Barth via fpc-pascal wrote:
Howard Page-Clark via fpc-pascal <mailto:fpc-pascal@lists.freepascal.org>> schrieb am Mo., 3. Feb. 
2020, 11:22:


FPC 3.0.4 compiles this code excerpt without a murmur:

== code ==

{$mode objfpc}{$H+}

type

   TSheetInfo = record
 name: String;
 tab: String;
 title: String;
 kind: TSheetKind; // an enumeration
 color: TColor;
   end;

   TBaseSheet = class(TTabSheet)
   protected
 FSheetInfo:  TSheetInfo;
 ...
   public
 constructor Create(aComponent: TComponent; aSheetInfo:
TSheetInfo);
virtual; reintroduce;
 ...
 property SheetKind: TSheetKind read FSheetInfo.kind; // <<
   end;

   TEntryGrid = class(TCustomStringGrid)
   private
 FParentSheet: TBaseSheet;
 ...
   public
 constructor Create(AOwner: TComponent; aParentSheet:
TBaseSheet);
reintroduce;
 ...
 property SheetKind: TSheetKind read
FParentSheet.FSheetInfo.kind; // <<
   end;

== code end ==

However, more recent FPCs (and trunk) reject this at the properties
(marked above <<) with the error "Record or object type expected".

Is there a modeswitch or other wheeze that will get recent FPCs to
accept dotted notation when specifying property read and write fields?


This is simply not allowed for class fields. That it was, was 
essentially a bug ( 
https://wiki.freepascal.org/User_Changes_Trunk#Property_field_access_lists_no_longer_allows_classes 
).
Either use records or (TP style) objects or use a getter. If you 
declare it as "inline" you can essentially get the same code (with the 
added bonus that you can raise an exception should the field be Nil).


Regards,
Sven


Thanks for the reference and clarification.

Howard



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


[fpc-pascal] Compiler treatment of dotted reference in class property

2020-02-03 Thread Howard Page-Clark via fpc-pascal

FPC 3.0.4 compiles this code excerpt without a murmur:

== code ==

{$mode objfpc}{$H+}

type

  TSheetInfo = record
    name: String;
    tab: String;
    title: String;
    kind: TSheetKind; // an enumeration
    color: TColor;
  end;

  TBaseSheet = class(TTabSheet)
  protected
    FSheetInfo:  TSheetInfo;
    ...
  public
    constructor Create(aComponent: TComponent; aSheetInfo: TSheetInfo); 
virtual; reintroduce;

    ...
    property SheetKind: TSheetKind read FSheetInfo.kind;  // <<
  end;

  TEntryGrid = class(TCustomStringGrid)
  private
    FParentSheet: TBaseSheet;
    ...
  public
    constructor Create(AOwner: TComponent; aParentSheet: TBaseSheet); 
reintroduce;

    ...
    property SheetKind: TSheetKind read FParentSheet.FSheetInfo.kind; // <<
  end;

== code end ==

However, more recent FPCs (and trunk) reject this at the properties 
(marked above <<) with the error "Record or object type expected".


Is there a modeswitch or other wheeze that will get recent FPCs to 
accept dotted notation when specifying property read and write fields?




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


Re: [fpc-pascal] Const attributes

2017-07-30 Thread Howard Page-Clark via fpc-pascal

On 30/07/17 19:55, Marcos Douglas B. Santos wrote:

I would like to instantiate my attribute only once inside constructor
and then it will be "const" or "final", I mean, immutable.
Today it is not possible, right? Any thoughts to the future?

It is not what you are asking for, but you can do this:

===code begin===
{$J-}
const
  INT: Integer = 9;

type

  TFoo = class
  strict private
function GetINT: Integer;
  public
property INT: Integer read GetINT;
  end;

function TFoo.GetINT: Integer;
begin
  Exit(INT);
end;
===code end===

The INT property is 'immutable' because it is read-only, and you cannot 
assign to its typed integer referent because of the {$J-}.

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

Re: [fpc-pascal] Array clearing

2017-04-04 Thread Howard Page-Clark via fpc-pascal

On 04/04/17 05:25, Ryan Joseph wrote:

Is it possible use FillChar on a multidimensional arrays?

arr: array of array of array of integer.
SetLength(arr, 3, 3, 3);
FillChar(arr[0], (3*3*3)*sizeof(integer), false);

I’m just getting crashes.


You can always use FillChar and its kin on specific 'nested' arrays like 
this


type
  TIntArray = array of Integer;
  TIntIntArray = array of TIntArray;
  TIntIntIntArray = array of TIntIntArray;

  procedure FillArray(const anArray: TIntIntIntArray; aValue: DWord);
  var
x, y: integer;
  begin
for x:=0 to High(anArray) do
  for y:=0 to High(anArray[x]) do
FillDWord(anArray[x][y][0], Length(anArray[x][y]), aValue);
  end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] IsValidIdent() and identifiers escaped with

2017-02-05 Thread Howard Page-Clark

Consider this program, which returns False:

program Project1;

uses sysutils;

var
  : boolean;

begin
  :=IsValidIdent('');
  WriteLn('IsValidIdent() evaluates to ', );
end.

Should sysutils.IsValidIdent() be updated to return True in this case?

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


Re: [fpc-pascal] How to split file of whitespace separated numbers?

2016-12-23 Thread Howard Page-Clark

On 23/12/16 08:14, Bo Berglund wrote:

Is there a quick way to split a string of whitespace separated values
into the separate members?
It is possible that a custom string parser (something along these lines) 
might improve your processing speed:


type
TDoubleArray = array of Double;

function StrToDblArray(const aString: string): TDoubleArray;
var
  c: Char;
  prevNumeric: boolean = False;
  sNum: string = '';
  number: double;

  function IsNumeric: boolean; inline;
  begin
Exit(c in ['.', '0'..'9']);
  end;

begin
  SetLength(Result, 0);
  for c in aString do begin
case IsNumeric of
  False: if prevNumeric then begin
if TryStrToFloat(sNum, number) then begin
  SetLength(Result, Length(Result) + 1);
  Result[High(Result)]:=number;
end;
sNum:='';
prevNumeric:=False;
 end;
  True: begin
  sNum:=sNum + c;
  if not prevNumeric then
prevNumeric:=True;
end;
end;
  end;
  if prevNumeric and TryStrToFloat(sNum, number) then begin
SetLength(Result, Length(Result) + 1);
Result[High(Result)]:=number;
  end;
end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Problem with objects

2015-12-23 Thread Howard Page-Clark

On 23/12/2015 11:40, Santiago A. wrote:

It's an object, not a class inherited from Tobject, so it hasn't create
constructor.


Try this:
program simpleObjConsole;

type

  { TSimpleArrayString }

  TSimpleArrayString=object
  public
 List:array of String;
 constructor Init;
 destructor Destroy;
 function AddedTextIndex(const aText: string): integer;
 function StringCount: integer;
  end;

  constructor TSimpleArrayString.Init;
  begin
SetLength(List, 0);
  end;

  destructor TSimpleArrayString.Destroy;
  begin
SetLength(List, 0);
  end;

  function TSimpleArrayString.AddedTextIndex(const aText: string): integer;
  begin
Result:=Length(List);
SetLength(List, Result+1);
List[Result]:=aText;
  end;

  function TSimpleArrayString.StringCount: integer;
  begin
Result:=Length(List);
  end;

type
  { TDerivedArrayString }

  TDerivedArrayString=object(TSimpleArrayString)
 other_field:integer;
  public
 constructor Init(anInt: integer);
  end;

  constructor TDerivedArrayString.Init(anInt: integer);
  begin
inherited Init;
other_field:=anInt;
  end;

  procedure TestDerived;
  var
idx, n: integer;
das: TDerivedArrayString;
  begin
das.Init(19);
idx:=das.AddedTextIndex('test string');
n:=das.StringCount;
WriteLn('das has ',das.StringCount,' string(s), and 
das.other_field=',das.other_field);

if (n > 0) then
  WriteLn('First string in das.List is "',das.List[idx],'" at 
index:',idx);

ReadLn;
das.Destroy;
  end;

begin
  TestDerived;
end.





---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: [fpc-pascal] How to work with reference-counted strings in dynamically created objects

2015-03-28 Thread Howard Page-Clark

On 28/03/2015 08:31, Sven Barth wrote:

Am 28.03.2015 06:51 schrieb Howard Page-Clark h...@talktalk.net
mailto:h...@talktalk.net:
 
  The following program, compiles and runs as expected using a
shortstring declaration in the TExample record.
  Could someone explain how to adapt it to cope with a TExample record
containing ansistrings?

[snip]
  procedure TExampleList.Initialize(aCount: integer);
  var
i: integer;
pex: PExample;
  begin
for i:=1 to aCount do begin
  GetMem(pex, SizeOf(TExample));
// use New(pex) instead of GetMem(...)
  pex^.Init(Format('Example#%d, Value=%d',[i, Random(100)]));
  FList.Add(pex);
end;
  end;
 
[snip]

 
  destructor TExampleList.Destroy;
  var
i: integer;
  begin
for i:=0 to FList.Count-1 do
  Freemem(FList[i], SizeOf(TExample));
// Use Dispose(PExample(FList[i])) instead of FreeMem(...)
FList.Free;
inherited Destroy;
  end;
 

It's best to always use New/Dispose if you work with records. Use
GetMem/FreeMem only if you work with unstructured memory areas or where
you don't really know the real size beforehand.

Regards,
Sven


Thank you

Howard

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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


[fpc-pascal] How to work with reference-counted strings in dynamically created objects

2015-03-27 Thread Howard Page-Clark
The following program, compiles and runs as expected using a shortstring 
declaration in the TExample record.
Could someone explain how to adapt it to cope with a TExample record 
containing ansistrings?


Howard

== code ==

program Project1;

{$mode objfpc}{$H+}
{$ModeSwitch advancedrecords}

uses classes, sysutils;

type

  { TExample }

  TExample = record
text: string; // program performs flawlessly with shortstring;
procedure Init(const aText: string);
  end;
  PExample = ^TExample;

  { TExampleList }

  TExampleList = class(TObject)
  private
FList: TFPList;
procedure Initialize(aCount: integer);
  public
constructor Create;
destructor Destroy; override;
procedure ListItems;
  end;

{ TExampleList }

procedure TExampleList.Initialize(aCount: integer);
var
  i: integer;
  pex: PExample;
begin
  for i:=1 to aCount do begin
GetMem(pex, SizeOf(TExample));
pex^.Init(Format('Example#%d, Value=%d',[i, Random(100)]));
FList.Add(pex);
  end;
end;

constructor TExampleList.Create;
begin
  FList:=TFPList.Create;
  Randomize;
  Initialize(4);
end;

destructor TExampleList.Destroy;
var
  i: integer;
begin
  for i:=0 to FList.Count-1 do
Freemem(FList[i], SizeOf(TExample));
  FList.Free;
  inherited Destroy;
end;

procedure TExampleList.ListItems;
var
  i: integer;
begin
  for i:=0 to FList.Count-1 do
WriteLn(PExample(FList[i])^.text);
  ReadLn;
end;

{ TExample }

procedure TExample.Init(const aText: string);
begin
  text:=aText;
end;


var
  exampleList: TExampleList;

begin
  exampleList:=TExampleList.Create;
  exampleList.ListItems;
  exampleList.Free;
end.




---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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


Re: [fpc-pascal] Common class type

2015-03-20 Thread Howard Page-Clark

On 20/03/2015 07:25, Torsten Bonde Christiansen wrote:

Hi.

Is there method in fpc to find the highest common class-type of two
derived classes?


I do not know of such a routine, though there may well be one somewhere.

I would have said that the highest common class would always be TObject, 
because a descendent class is usually spoken of as 'lower' rather than 
'higher' than its ancestor.


I think the following does the job (perhaps rather inefficiently).

function LowestCommonClass(class1, class2: TClass): TClass;
var
  sl: TStringList;
  cp: TClass;

  function FoundClassInList(aClass: TClass; out aCommonClass: TClass): 
boolean;

  var
i: integer;
s: string;
  begin
Result:=False;
aCommonClass:=nil;
s:=aClass.ClassName;
for i:=0 to sl.Count-1 do
  if SameText(sl[i], s) then begin
aCommonClass:=TClass(sl.Objects[i]);
Exit(True);
  end;
  end;

begin
  Result:=nil;
  sl:=TStringList.Create;
  try
sl.AddObject(class1.ClassName, TObject(class1));
cp:=class1.ClassParent;
while (cp  nil) do begin
  sl.AddObject(cp.ClassName, TObject(cp));
  cp:=cp.ClassParent;
end;

cp:=class2;
while (cp  nil) do begin
  if FoundClassInList(cp, Result) then
Exit;
  cp:=cp.ClassParent;
end;

  finally
sl.Free;
  end;
end;



---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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


Re: [fpc-pascal] character escaping with ^LETTER

2015-01-19 Thread Howard Page-Clark

On 19/01/2015 13:29, Dmitry Boyarintsev wrote:


Not sure which pascal its inherited from... but Delphi 7 does
compile it too.


It was certainly a feature of the first TurboPascal, and perhaps was in 
even earlier Pascal compilers, enabling simple insertion of control 
characters from the keyboard.
Later superseded by the control string syntax (#nnn) which gave access 
to all 8-bit ASCII values, it was retained by Borland for backwards 
compatibility reasons. A complication for parsers since ^ has other 
meanings of far more significance in most Pascal code.



---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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


Re: [fpc-pascal] How can you convert an enum value to string?

2014-12-13 Thread Howard Page-Clark

On 13/12/2014 02:50, silvioprog wrote:
...

for i := 1 to c do
 getenumname(typeinfo(tenum), integer(en));

...

I think for a fairer comparison with WriteStr the compared GetEnumName 
call should be


...
for i := 1 to c do
  s := GetEnumName(TypeInfo(tenum), integer(en));
...

Mind you, on my system, such an adapted GetEnumName assignment remains 
faster than WriteStr.


Howard

---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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


Re: [fpc-pascal] else and otherwise in a case statement

2014-12-11 Thread Howard Page-Clark

On 11/12/2014 21:07, Mark Morgan Lloyd wrote:

I've been doing a bulk replace of 'case..else' to 'case..otherwise' to
eliminate possible ambiguities that have bitten me in the past, and have
noticed something interesting under 2.6.4 on x86 Linux.


How can else be ambiguous within a case statement?

Howard


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

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


Re: [fpc-pascal] got untyped expected procedure variable type of procedure(TObject) of object; Register

2014-07-16 Thread Howard Page-Clark

On 15/07/2014 19:56, rupert THURNER wrote:


type
   TForm1 = class(TForm)
 procedure SpeedButton1Click(Sender: TObject);

procedure TForm1.SpeedButton1Click(Sender: TObject);

procedure TForm1.CreateButton(t: Integer;l: Integer;btext: String; machine:
String);
var
   button: TSpeedButton;
begin
   button:=TSpeedButton.Create(self);
   button.OnClick:=SpeedButton1Click(button);


There are two errors.

button should be a field in the TForm1 class. Declared as a local 
variable it will be inaccessible after CreateButton() exits.


If using {$mode objfpc} the OnCick assignment should be

button.OnClick:=@SpeedButton1Click;

with no parameter specified. In delphi mode you don't need the @ operator.

Howard

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


Re: [fpc-pascal] Printing object

2014-06-07 Thread Howard Page-Clark

On 07/06/2014 15:49, Michael Van Canneyt wrote:



On Sat, 7 Jun 2014, Krzysztof wrote:


Hi,

I need to analyze a lot of big objects (a lot of properties, global
vars etc). Looking for easy way to print object info in
format:

TObject
  Property/VarName = value
end;

It should also step into subobjects. Looking at typeinfo but can't
find method for this.


This is done in classes unit. It requires a tcomponent, though.
the jsonrtti and rttiutils also can do this.


As the unit names indicate these utilities cover published properties.
I think to get equivalent information for public and protected 
properties you have to roll your own routines (if that's what Krzysztof 
needs).


Howard

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


Re: [fpc-pascal] Cloning objects?

2014-03-19 Thread Howard Page-Clark

On 19/03/2014 22:01, Timothy Groves wrote:

Is there a drop-dead simple way to clone an object?


The convention established in Delphi for TPersistent descendants is to 
provide an Assign method to do this, so for TPersistent descendants 
(components, controls etc.) you can just override this method.
I know of no such method provided above TPersistent in the TObject 
hierarchy.


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


[fpc-pascal] Does RTTI offer any method parameter information?

2014-02-01 Thread Howard Page-Clark

In a situation where

  PPropInfo^.PropType^.Kind=tkMethod

does RTTI enable you to determine the number and/or types of the 
parameters that method uses (if any)?
If not, is there a programmatic way to determine that information apart 
from parsing the source?


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


Re: [fpc-pascal] Does RTTI offer any method parameter information?

2014-02-01 Thread Howard Page-Clark

On 01/02/2014 18:54, Sven Barth wrote:

On 01.02.2014 19:10, Howard Page-Clark wrote:

In a situation where

   PPropInfo^.PropType^.Kind=tkMethod

does RTTI enable you to determine the number and/or types of the
parameters that method uses (if any)?


Yes, please take a look at the tkMethod part of the case inside
TTypeData in $fpcdir/rtl/objpas/typinfo.pp
There are AFAIK no functions yet that simplify the access though. Maybe
someone else has already written a wrapper for it.


I should have known to look at the source. Thanks Sven for pointing me 
to the correct place.


H

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


Re: [fpc-pascal] Pure FPC ?

2014-01-26 Thread Howard Page-Clark

On 26/01/2014 21:20, Fred van Stappen wrote:

Does it exist a option to compile fpc without Delphi compatibility ?

If no, what do you think about that ?

I know, it will be lot of work (like create a Delhi_Compatiblizer
class...) but it could be great for people who want a lighter
compiler...(like me, who have already done, since years ago, the fpc
migration)...


What extent of Delphi incompatibility would satisfy you?

{$objfpc}
has offered 'mild' incompatibility for many years.
What additional incompatibilities are you looking for?

Howard


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


Re: [fpc-pascal] Strange message about mixed signed expression

2014-01-21 Thread Howard Page-Clark

On 21/01/2014 17:33, Jürgen Hestermann wrote:

I always wondered why I get a compiler message for the following code
...

if i+length(M)length(F) then
...
But where are signed expressions involved?


Length is declared in the compiler/RTL to return an integer result.

Howard


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


[fpc-pascal] minor glitch in phrasing of rarely seen compiler warning

2014-01-16 Thread Howard Page-Clark

I recently wrote code that produced this Warning

... Warning: compiler switches aren't supported in \ styled comments

Should this not read as follows?

Warning: compiler switches aren't supported in / styled comments

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


Re: [fpc-pascal] Documentation, syntax diagrams

2014-01-08 Thread Howard Page-Clark

On 08/01/2014 18:16, Jürgen Hestermann wrote:


Today I found this type definition in some FreePascal sources:

TypeReal =type Double;

I wondered what the second “type” keyword means here (I have never seen
this before).


You are being rather obtuse.
Ignore the diagrams in the docs if they don't help you.

The double use of type here simply means that the Real type is being 
defined as an alias for double. The two type identifiers now mean 
exactly the same thing as the = indicates.


The documentation for hint directives gives three clear and explicit 
examples of different hint directives showing how to declare them and 
the compiler-generated hints that result from their use.


What more do you want?

Howard



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


Re: [fpc-pascal] Documentation, syntax diagrams

2014-01-08 Thread Howard Page-Clark

On 08/01/2014 20:01, Sven Barth wrote:

On 08.01.2014 19:40, Howard Page-Clark wrote:

On 08/01/2014 18:16, Jürgen Hestermann wrote:


Today I found this type definition in some FreePascal sources:

TypeReal =type Double;

I wondered what the second “type” keyword means here (I have never seen
this before).


You are being rather obtuse.
Ignore the diagrams in the docs if they don't help you.

The double use of type here simply means that the Real type is being
defined as an alias for double. The two type identifiers now mean
exactly the same thing as the = indicates.


No, an alias would be

=== code begin ===

type
   Real = Double;

=== code end ===

Using the type behind the = tells the compiler to declare a new type
based on the right side. So a Double and a Real are not assignment
compatible and can have different sets of operator overloads.


Thanks for the clarification. That is a distinction worth drawing 
attention to in the documentation, and its relevance when writing 
overloaded routines.

Looks like the obtuseness is at this end, as well as at Jürgen's.

Howard

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


[fpc-pascal] Over-zealous Warning about dynamic string initialization

2013-11-01 Thread Howard Page-Clark

The following program:

program Project1;

{$mode objfpc}{$H+}

var
  s:ansistring;

begin
  WriteLn('s ',s,' always seems to be initialized to ');
end.

produces a Warning

Warning: Variable s does not seem to be initialized

Can this Warning be disabled for compiler-managed variables?

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


Re: [fpc-pascal] Breaking Pascal source lines

2013-09-06 Thread Howard Page-Clark

On 06/09/2013 14:10, Mark Morgan Lloyd wrote:

I'm sure there isn't a single right answer to this question, but if
transferring Pascal source to a system that enforces short lines (e.g.
78 chars + CRLF) what's the best automatic breaking rule?

One possibility is obviously to break after the rightmost space, but is
it valid to break after e.g. . (if not followed by a digit), ^ and
possibly others?

Syntax errors are acceptable. Truncation isn't.


Is it valid...? Yes.
The compiler largely ignores line endings and line breaks (since they're 
inserted mainly for formatting, not syntax purposes).
One exception is string constants, so your parser will have to track the 
' character and ensure a corresponding later match within the short 
line, or else insert a forced concatenation.

The code

type
PInteger = ^
integer;

has readability shortcomings, but compiles without a murmur.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] When does a reference counted object get freed automatically, and when not?

2013-08-10 Thread Howard Page-Clark
I've been exploring interfaces a bit, and fail to understand when 
automatic destruction of an object is precipitated by the compiler, and 
when not.
Consider the lifetime of the two instances i1 and i2 in the following 
program. It seems that i2 (called in a method of i1) is freed 
automatically, but i1 is not.


== code begin ==

program integerInterface;

{$mode objfpc}{$H+}

type
  ISortableInteger = interface
  ['{D38A748E-F889-4A2A-9E3C-5154D493061C}']
function Compare(anIntf: ISortableInteger): integer;
procedure SetValue(aValue: int64);
function GetValue: int64;
property Value: int64 read GetValue write SetValue;
  end;

  { TSortableInteger }

  TSortableInteger = class(TInterfacedObject, ISortableInteger)
  strict private
Fint: int64;
procedure SetValue(aValue: int64);
function GetValue: int64;
  public
function Compare(anIntf: ISortableInteger): integer;
property Value: int64 read GetValue write SetValue;
  end;

{ TSortableInteger }

function TSortableInteger.Compare(anIntf: ISortableInteger): integer;
begin
  if Fint  anIntf.Value then
Result := 1
  else if Fint = anIntf.Value then
Result := 0
  else
Result := -1;
end;

function TSortableInteger.GetValue: int64;
begin
  Result := Fint;
end;

procedure TSortableInteger.SetValue(aValue: int64);
begin
  Fint := aValue;
end;

var i1, i2: TSortableInteger;

begin
  i1 := TSortableInteger.Create;
  i1.Value := 21;
  i2 := TSortableInteger.Create;
  i2.Value := 22;
  WriteLn('i1 (21) compared to i2 (22) is ',i1.Compare(i2));

  i1.Free; // why is this necessary with a reference counted interface?

  ReadLn;
end.

== code end ==
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] OT: Re: http://www.freepascal.org/future.var

2013-06-06 Thread Howard Page-Clark

On 06/06/2013 08:32, Mark Morgan Lloyd wrote:

Reinier Olislagers wrote:

On 6-6-2013 7:52, Florian Klämpfl wrote:

Reinier Olislagers
reinierolislagers-re5jqeeqqe8avxtiumw...@public.gmane.org schrieb:


On 5-6-2013 22:02, Florian Klämpfl wrote:

I'am opposed to an LLVM backend but if Jonas implements one I can and
will not influence this :)

That's clear enough, thanks!

Of course I meant  I can not and will not ...


Sure, I understood you: German and Dutch are much alike in this
particular construction where you leave out one not/nicht/niet, I
think ;)


English is the same. Don't worry about it.

I'm not a good enough linguist to know if English is the same, but 
Florian's original statement in English is ambiguous. It could be taken 
to mean I can influence an LLVM implementation, but I will not, or it 
could be taken to have an implied earlier not to mean I cannot and 
will not influence...
However it is a very curious construction in English, which immediately 
makes the reader think What does he mean exactly?

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


Re: [fpc-pascal] Re: two questions about dynamic array

2013-03-14 Thread Howard Page-Clark

On 14/03/13 7:59, Mattias Gaertner wrote:


Xiangrong wanted to know if the above array is initialized.
If you want to test that then you have to either single step via
the debugger or to compare the allocated memory before and after.
The problem is that you do not know the memory position before the
allocation.
You can try to create the class, change it, free it and
allocate it again. If the two instances are at the same position, then
you can check for 0 or nil.


Thanks for the clear explanation. I now see that the question is about 
the data stored in memory, not about the memory address.


Howard

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


Re: [fpc-pascal] Re: two questions about dynamic array

2013-03-13 Thread Howard Page-Clark

On 12/03/13 8:30, Xiangrong Fang wrote:

TMyClass = class
 myarray: array[0..100] of Integer;
end;

You could answer such questions yourself:

program Project1;

{$mode objfpc}

type

TMyClass = class
  myarray: array of Integer;
end;

var my:TMyClass;
begin
  my:=TMyClass.Create;
  try
   writeln('After creation the value of my.myarray is 
',PtrUInt(my.myarray));

   SetLength(my.myarray, 0);
   writeln('After SetLength(), value of my.myarray is 
',PtrUInt(my.myarray));

  finally
my.Free;
  end;
  ReadLn;
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: two questions about dynamic array

2013-03-13 Thread Howard Page-Clark

On 13/03/13 9:50, Mattias Gaertner wrote:

On Wed, 13 Mar 2013 09:35:43 +
Howard Page-Clark h...@talktalk.net wrote:


On 12/03/13 8:30, Xiangrong Fang wrote:

TMyClass = class
  myarray: array[0..100] of Integer;
end;

You could answer such questions yourself:


Not with this simple test.



[...]
my:=TMyClass.Create;
try
 writeln('After creation the value of my.myarray is
',PtrUInt(my.myarray));


Could you show a more complex test that would give a satisfactory 
answer to the OP's questions?


Howard

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


Re: [fpc-pascal] Set size limit

2013-03-10 Thread Howard Page-Clark

On 10/03/13 2:12, Jonas Maebe wrote:


There is a already a test for larger set support: 
http://svn.freepascal.org/svn/fpc/trunk/tests/test/tset6.pp

Nobody has worked yet on implementing it, but if anyone thinks it's easy to do, 
please go ahead. For larger sets,
 especially if they are sparse, a simple hashtable-based class would 
probably be much faster and memory efficient
 than simply extending the default implementation though. With operator 
overloading and generics you might even be

 able to use more or less the same syntax as with built-in sets.

There is a generic hashset implementation in the stl package, which has 
no 256-element limit on set size. See

...\source\packages\fcl-stl\src\ghashset.pp
A .tex documentation file is included along with a hashsetexample.pp

Howard

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


Re: [fpc-pascal] Result: string

2013-03-05 Thread Howard Page-Clark

On 04/03/13 10:33, José Mejuto wrote:


The code that makes me wonder something is wrong is this one:

---
{$mode objfpc}
{$h+}

procedure TheB(var aTheA: string);

begin
   aTheA:=aTheA+'A';
end;

function TheA(): string;

begin
   //Result:='';
   TheB(Result);
end;

Var
   C : String;

begin
   C:='B';
   C:=TheA;
   C:=TheA;
   Writeln('= ',C,'');
end.


For me (win32, FPC 2.6.2) the output is identical (= A) whether or not 
Result in TheA() is initialised manually or not. Perhaps 2.7.1 has a 
regression here if it differs for you?


Howard

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


Re: [fpc-pascal] Result: string

2013-03-04 Thread Howard Page-Clark

On 04/03/13 8:23, Juha Manninen wrote:

On Mon, Mar 4, 2013 at 9:21 PM, José Mejuto joshy...@gmail.com wrote:

What's the expected output of this code ?

function TheA(): string;
begin
   Result:=Result+'A';
end;

writeln(TheA());

I thought that when the result type is an automated one its value gets
initialized... Maybe I'm wrong...


Yes you are wrong. It is very illogical because a local string
variable is initialized to be empty but the return value is not.
Delphi has the same problem.

I once made even a report about it:
   http://bugs.freepascal.org/view.php?id=20907


That report says the issue was assigned to Jonas and fixed in revision 
20427 (ver 2.6.1).
I find the current release (2.6.2) initialises a string function result 
to EmptyStr as you would hope.



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


Re: [fpc-pascal] fpc registry unit

2013-03-01 Thread Howard Page-Clark

On 01/03/13 5:34, John Lee wrote:

Think I'm missing something! I need the/a fpc registry unit - I can't
seem to find it on svn - lots of references to it!  Pls send or point me
to it.


If you use Lazarus, just make sure FCL is a declared dependency in your 
project, and add


uses registry;

to the relevant unit.

registry.pp is in ...\packages\fcl-registry\

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


Re: [fpc-pascal] FPC Lazarus used for teaching down under

2013-02-28 Thread Howard Page-Clark

On 28/02/13 12:19, Marcos Douglas wrote:


Very good!
But I'm afraid if someone thinking if Pascal is just for kids 5-9
years old... not here, but out there!  :)

Thank you for share it.


Year 5-9 kids refers to their school year, not their calendar age. In 
the UK a Year 9 teenager is 13 or 14 years old. I imagine the school 
year numbering scheme in Australia is similar.


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


[fpc-pascal] abstract classes

2013-01-20 Thread Howard Page-Clark
FPC allows the Delphi-compatible class abstract syntax, but does not 
seem to prevent instantiation of such a class.

The following code compiles and runs satisfactorily (FPC version 2.6.0)
Does trunk prevent this compiling?

program Project1;

{$mode objfpc}{$H+}

type
  TAbstractClass = class abstract
   class function GetID: integer; static;
  end;

class function TAbstractClass.GetID: integer;
begin
  Result:= 10;
end;

var
  ac: TAbstractClass;

begin
  ac:= TAbstractClass.Create;
  WriteLn(ac.GetID);
  ReadLn;
  ac.Free;
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] class destructor not recognised

2013-01-07 Thread Howard Page-Clark

On 07/1/13 2:42, Paul Ishenin wrote:

You don't understand.

Class destructor is called automatically like finalization section of a
unit. You can't call it directly.


Thanks for the clarification. I was confused by the fact that the 
writeln called in the class destructor is not displayed. But I guess it 
is executed so late in the process that it cannot be seen?


Howard

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


[fpc-pascal] class destructor not recognised

2013-01-06 Thread Howard Page-Clark
The following program compiles and gives output as expected, but if the 
lines that call the class destructor are uncommented it fails to compile 
with the error identifier idents no member Finalise


program classConstructor;

{$mode objfpc}

uses Classes;

type

 TXClass = class
class var int1: integer;
class constructor Init;
class destructor Finalise;
   end;

class constructor TXClass.Init;
begin
  int1:=-1;
end;

class destructor TXClass.Finalise;
begin
  int1:=0;
  writeln('TXClass.Finalise; int1 is ',int1);
end;

var x: TXClass;

begin
  x:= TXClass.Create;
  WriteLn('cc.int1 is ', x.int1);
//  TXClass.Finalise;
//  x.Finalise;
  x.Free;
  TXClass.int1:=1;
  WriteLn('TXClass.int1 is ', TXClass.int1);
  ReadLn;
end.

Am I not understanding how to use a class destructor, or is this a bug?

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


[fpc-pascal] Codetools and C-style constructs

2012-12-18 Thread Howard Page-Clark
Looking through some of the codetools sources makes me wonder if the 
codetools overlooks some C-style FPC operators.


KeywordFuncLists.pas, for instance, seems not to know about , ,
+=, -=, *=, /=.

Or are these operators are catered for elsewhere in the codetools?

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


Re: [fpc-pascal] Codetools and C-style constructs

2012-12-18 Thread Howard Page-Clark

On 18/12/12 10:56, Mattias Gaertner wrote:


Looking through some of the codetools sources makes me wonder if the
codetools overlooks some C-style FPC operators.

KeywordFuncLists.pas, for instance, seems not to know about , ,
+=, -=, *=, /=.


I added the  and .
The others are assignment operators. AFAIK they can not be overloaded.


Or are these operators are catered for elsewhere in the codetools?


Can you give an example, in what context you are missing an operator?


I have not encountered any errors in relation to codetoools handling of 
these operators, and I had not understood the overload orientation of 
the routines in that unit. I'm just trying to fathom how some of the 
functionality works (from browsing the source), piece by piece.


Howard

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


Re: [fpc-pascal] Property alias

2012-12-07 Thread Howard Page-Clark

On 07/12/12 2:50, Krzysztof wrote:

Hi,

Interfaces can have aliases for functions:

 Function MyOtherFunction : Integer;
 Function IMyInterface.MyFunc = MyOtherFunction;

Can normal object have aliases for properties? For example,
TControl.Caption. I would like to publish this property in my descendant
as MyExtraText. Is this possible?


You can, of course, define a MyExtraText property with a setter and 
getter that refer to an existing property (or data field if it is 
accessible).


Howard

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


[fpc-pascal] Case of documentation

2012-11-24 Thread Howard Page-Clark

Describing the Case statement The FPLanguageReference.pdf 10.2.2 says:

The constants appearing in the various case parts must be known at 
compile-time, and can be of the following types : enumeration types, 
Ordinal types (except boolean), and chars.


Why the except boolean? I find the compiler happily accepts a boolean 
expression as a case selector, as well as True and False as 
corresponding labels, and the resulting compiled code performs as you 
would expect.


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


Re: [fpc-pascal] Is it possible to redefine FreePascal types?

2012-11-21 Thread Howard Page-Clark

On 21/11/12 7:49, Kenneth Cochran wrote:

Yes.

type newString = type string;

Any function that accepts newString as a parameter will cause a
compilation error if you try to pass a normal string. You'll have to
cast it to newString first.


This is not the case, as the following program demonstrates. The 
compiler does not even blink.


program Project1;

{$mode objfpc}{$H+}

type TnewString = type string;

function NewStringFn(ns: TnewString): integer;
var c: Char;
begin
  Result := 0;
  for c in ns do
   if (c#0) then inc(Result);
end;

var s:string = 'ansistring';
ns:TnewString = 'new string';
begin
  writeln('The new string length is ',NewStringFn(ns));
  writeln('The old string length is ',NewStringFn(s));
end.

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


Re: [fpc-pascal] releasing commercial components as PPU files

2012-10-22 Thread Howard Page-Clark

On 22/10/12 3:17, Graeme Geldenhuys wrote:

On 2012-10-22 14:59, Vincent Snijders wrote:


I am more optimistic than Michael. Because the same source is used,
the CRC is the same and no recompile is done.



Thanks Vincent, things are looking better and better.


You might be interested to follow the forum thread about the 
Delphi-based Raudus tool (Russian developer) which has a Lazarus port on 
a closed source binary-only basis.

http://www.lazarus.freepascal.org/index.php/topic,17953.30.html

Howard

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


Re: [fpc-pascal] Function for checking correct file name

2012-09-14 Thread Howard Page-Clark

On 14/9/12 2:43, Mattias Gaertner wrote:


   c: set of Char = ['','',':','','/','\','|','?','*', '%', '.'];



  But several of those are fine in filenames- just inadvisable since they
  need special quoting/escaping to get past the shell. As does ' ' which
  isn't in your list :-)

And it does not check for #0..#31, #127.


As is so often the case, a truly cross-platform solution requires a good 
deal more care and research (and cross-platform experience) than simply 
extending a Windows-only solution.


Howard

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


Re: [fpc-pascal] WeekDay outdated?

2012-08-13 Thread Howard Page-Clark

On 13/8/12 9:56, Jürgen Hestermann wrote:

I am not able to use this function:

http://www.freepascal.org/docs-html/rtl/dos/weekday.html
nor can I find it in the sources.
Does it still exist?
If yes, how to use it? Which unit? DOS does not work.

You will find what you need at unit dateutils.


When I add dateutils to my units Weekday isn't found either (I already
tried this yesterday).


Sysutils has an integer DayOfWeek function, and dateutils has a word 
DayOfTheWeek function.
Both take a TDateTime parameter (rather than the separate year, month, 
day parameters of the old dos unit).


Howard


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


Re: [fpc-pascal] How to find a graphic element in the form editor?

2012-08-07 Thread Howard Page-Clark

On 07/8/12 1:10, Jürgen Hestermann wrote:

When I want to add a graphic element like TFileNameEdit which I have
already
used in other programs in the form editor I don't know how to find it in
the menu.


Although this is the fpc list you mention a LCL component and the form 
editor, so I presume you are using Lazarus.
Use View | Components (shortcut Ctrl Alt P), and type 'filen' in the 
filter edit.

It takes you straight there.

Howard

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


[fpc-pascal] /docs-html/rtl/system/get_caller_addr.html

2012-08-07 Thread Howard Page-Clark
There is a typo in this documentation. The Description field refers to 
get_caller_frame when get_caller_addr is surely meant.


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


Re: [fpc-pascal] Re: printing each Friday the 13 using Pascal

2012-08-06 Thread Howard Page-Clark

On 06/8/12 1:32, leledumbo wrote:

Minor amendment needed to leledumbo's code to give Friday, and a five 
year range:


uses SysUtils;

const startYr: word = 2012;

var dt: TDateTime;
year, month: word;

begin
  for year in [0..4] do
   for month in [1..12] do
begin
  dt := EncodeDate(startYr + year, month, 13);
  if (DayOfWeek(dt) = 6) then
   begin
 writeln(FormatDateTime(', DD-MM-',dt));
   end;
end;
end.

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


Re: [fpc-pascal] Get all caller adresses of a procedure/function

2012-08-06 Thread Howard Page-Clark

On 06/8/12 3:26, Rainer Stratmann wrote:

procedure p1;
begin
  ...
end;



How to get all caller adresses of p1 in a program before p1 is executed?

For example p1 is called from 20 different places in a program.
Then I need the 20 caller adresses.


if by address you mean line number, then use the Find In Files dialog. 
Close all files in the Source Editor except the one containing p1 
procedures.

In the Text to Find field type p1.
In the Where radiogroup select Search all open files.
Should give you a list of every occurrence of p1.

Howard

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


Re: [fpc-pascal] Program without window but messages

2012-04-24 Thread Howard Page-Clark

On 24/4/12 5:25, Jürgen Hestermann wrote:

I wanted to write a program that has no window but may show messages to
the user.
I have lots of such programs written with Virtual Pascal but I am
struggling
to do the same with Free Pascal/Lazarus.

A simple test program would look like this:


program Test;
{$mode objfpc}{$H+}
uses Interfaces,Forms,Windows,SysUtils,Dialogs;
{$R *.res}

begin
ShowMessage('TEST');
end.




Creating a console program is not an option because it will create a
console window which I don't need.

Anybody who knows why it is like that?


A GUI program requires a main window since that is the avenue for user 
interaction. You can hide that window (not ignore it) as in the 
following program, which compiles and runs. However, I can't myself see 
the use of such truncated GUI functionality. Once the main form is 
hidden, I see no way for the user ever to get back to it.


program Project1;

{$mode objfpc}{$H+}

uses
  Interfaces, Forms, Unit1, Dialogs;

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Form1.Hide;
  ShowMessage('TEST');
  Form1.Close;
  Application.Run;
end.

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


Re: [fpc-pascal] XML parser

2012-04-07 Thread Howard Page-Clark

On 06/4/12 7:38, Juha Manninen wrote:


Now I am looking for a proper XML parser for Delphi, for big XML files.
The default Delphi parser, using MS DOM, chokes badly. 4 GB memory is
not enough for it.


Another option is kbmMW from

http://www.components4programmers.com/products/index.htm

The entry level product is free. It has a very capable XML DOM parser 
and generator, in addition to lots of other functionality.


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


Re: [fpc-pascal] (no subject)

2012-02-24 Thread Howard Page-Clark

On 23/2/12 4:17, Everton Vieira wrote:

Is there any plans to implement public procedures/function of a class
that can be used without been necessary to create the class?


I presume you know about class methods such as TObject's

class function ClassName : shortstring;

that you can use like this

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessageFmt('Class name of TEdit is %s', [TEdit.ClassName]);
end;

without needing to instantiate a TEdit instance?

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


Re: [fpc-pascal] Pass array of record as parameter

2012-02-09 Thread Howard Page-Clark

On 09/2/12 5:17, Zaher Dirkey wrote:

Hi,

TInfo=record
   s: string;
   i: integer;
end;

function func1(a: array of TInfo);

how can i pass the parameter to that function?


You have to declare the parameter type independently of the function 
declaration. You can also do it without declaring an additional pointer 
type (which is also one way to do it), since dynamic arrays already have 
an implicit pointer. Something like this:


type
  TInfo=record
s: string;
i: integer;
  end;

  TInfoArr = array of tInfo;

procedure proc1(a: TInfoArr);

implementation

procedure TForm1.Button1Click(Sender: TObject);
var rec: TInfo;
infoArr: TInfoArr = nil;
begin
  SetLength(infoArr, 2);
  rec.i := 1; rec.s := 'test1';
  infoArr[0] := rec;
  rec.i := 2; rec.s := 'test2';
  infoArr[1] := rec;
  proc1(infoArr);
end;

procedure proc1(a: TInfoArr);
var s: string = '';
i: integer;
begin
  for i := Low(a) to High(a) do
   s := s + Format('TInfo%d: s=%s, i=%d ',[i, a[i].s, a[i].i]);
  Showmessage(s);
end;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] procedure variable and inc/dec procedures

2012-01-17 Thread Howard Page-Clark

On 17/1/12 9:47, ik wrote:


var
   a : procedure(var x : TOrdinal);
   b : procedure(var x : integer);

begin
   a := @inc;
   b := @dec;



Why doesn't the compiler like the above code ?


Inc and Dec are internal compiler routines, more like macros than true 
functions. They are not coded as library functions you can locate in the 
RTL at an addressable location.

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


Re: [fpc-pascal] fpGUI Toolkit v0.8 release for FPC 2.4.4 2.6.0-rc

2012-01-05 Thread Howard Page-Clark

On 05/1/12 8:37, Graeme Geldenhuys wrote:


Thanks Paul. I'm almost ready to push the new website live.  I'll make
sure I update your embedded section.

Regarding your previous message about documentation. My goal this year
is to complete the API documentation, and also start writing a free
Developing with fpGUI book. I want to split the chapters in the book
into sections of Beginner, Intermediate and Advanced. I don't want the
book to be a copy of the API documentation, but rather a more in-depth
usage of various fpGUI features, and also covering the tools included
with fpGUI. Including a chapter on Embedded Development is definitely
a good idea, and so too are the Debugging you mentioned.

If anybody wants to contribute towards the book, feel free to contact
me via private email, or via the fpGUI newsgroups.


Hi
It's possible I could help with book proofreading, and editing of 
content written by you or others.
I contributed in this way to the English version of Lazarus the 
Complete Guide published last year from a German original.
I was able to pull together text from German, Belgian, Scandinavian, 
Brazilian and Dutch authors and produce reasonably fluent UK English 
with a consistent style. (I was an editor/corrector, not principally a 
translator). Of course some authors baulked at having their text 
massaged in this way, but I think the end result justified the editorial 
input.


yours

Howard

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


Re: [fpc-pascal] alias a function + overload 'in'

2011-12-18 Thread Howard Page-Clark

On 18/12/11 5:07, David Emerson wrote:

1. Is it possible to make an alias to a function ... so rather than just
re-calling with the same parameters, it's actually the same thing? like the way
we can do, e.g., type natural = cardinal, or const GG = 6, but with a function?


There's always the simple-minded calling of identical code such as

function Name: string;
  begin
result := 'Name';
  end;

  function NameAlias: string;
  begin
Result := Name;
  end;

Perhaps you were looking for something more sophisticated?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] video unit and pseudo-graphic characters on Windows

2011-07-04 Thread Howard Page-Clark

On 04/7/11 7:16, Calinov Valentin wrote:

Hi,

I need to display pseudo-graphic characters on Windows XP (English
version) using video unit
from fpc-2.4.4 .
When I use Raster Fonts they are displayed correctly
but when I use Lucida Console font, small squares are displayed instead.
The current code page displayed by chcp command is 437.

Is there any workaround for Lucida Console font ?


Many fonts lack graphics for certain code points, particularly code 
points that are not not normally used for text. Points lacking in a font 
are substituted by Windows with squares or ?? if you force display of a 
character the font lacks. Raster Fonts is one of the few, as you 
discovered, that supplies graphs for unusual code points.

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


Re: [fpc-pascal] Initialize object variables

2011-04-28 Thread Howard Page-Clark

On 28/4/11 10:00, Jürgen Hestermann wrote:



Darius Blaszyk schrieb:

Is there any way to initialize object variables, other than writing an
init method?
So something like:
myobj = object
myvar: word = $;
end;

I don't think so.
An object is a pointer to a data structure on the heap.
At compile time, this data structure is not yet allocated.

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

I think objects are allocated on the stack (not the heap), but that does 
not help in circumventing the init method to initialize them.


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


Re: [fpc-pascal] Pre-initialising a TStringList

2011-02-06 Thread Howard Page-Clark

On 06/2/11 1:55, Mark Morgan Lloyd wrote:

Given one or more lines of text which are known at compilation time, and
without the requirement to internationalize (these are, by RFC, US
ASCII), what is the best way to get them into a TStringList?


Perhaps there are better ways than the straightforward way?

const StringsToUse: string = 'Line 1'+LineEnding+
 'Line 2'+LineEnding+
 // + ...
 'Line n';

var  FPreInitialisedSList: TStringList;

begin
  FPreInitialisedSList := TStringList.Create;
  FPreInitialisedSList.SetText(PChar(StringsToUse));

  // ...

  FPreInitialisedSList.Free;

H

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


Re: [fpc-pascal] Re: [Lazarus] complex ini like syntax parser

2011-01-06 Thread Howard Page-Clark

On 06/1/11 2:49, Gene Buckle wrote:

On Wed, 5 Jan 2011, leledumbo wrote:



If you want something fast, pyacc and plex distributed with fpc can be an
option. But I suggest writing your own since that way you'll have a full
control of its features.


Is there an fpc version of TIniFile?

g.


look in
..fpc\version_number\source\packages\fcl-base\src\inifiles.pp

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


Re: [fpc-pascal] constant records as default parameters

2010-12-30 Thread Howard Page-Clark

On 30/12/10 7:40, David Emerson wrote:

I'd like to use a constant record as a default parameter. Is there some way to
do this? Here's my use case:

type
   lt_ints = record
 left, top : longint;
 end;

const
   lt_zero : lt_ints = (left:0; top:0);

procedure do_something (const offset_lt : lt_ints = lt_zero);


The procedure declaration gives an error (illegal expression).

I assume the trouble is that lt_zero cannot be used as a default parameter
value, because it is not truly a constant: it is an initialized variable.

Perhaps my real question is: how do I make a constant record which is truly
constant, rather than an initialized variable?


AFAIK default parameters can only be simple types, not complex types 
like records. Although, I did get the following program using a default 
class parameter to compile and run. (And I thought you could not have 
var default parameters).


unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
  end;

  Tduo = class
  public
top, left: longint;
  end;

var  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
var duo: Tduo=nil;

  procedure Doit(var du: TDuo = nil);
  begin
if du = nil then
 begin
 du := TDuo.Create;
 du.top:=2;
 end;
  end;

begin
  Doit(duo);
  ShowMessageFmt('duo.top has value %d',[duo.top]);
  duo.Free;
end;

end.

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


Re: [fpc-pascal] evaluation of set constant

2010-12-22 Thread Howard Page-Clark

On 22/12/10 1:15, Torsten Bonde Christiansen wrote:

type
   TMyType = (a, b, c ,d);
   TMyTypes = set of TMyTypes;

const
   SetX:TMyTypes = (a, b);
   SetY:TMyTypes = (c, d);
   SetCombined: TMyTypes = SetX + SetY;   // this gives me an Error: Illegal 
expression


Because you have not declared your sets with the correct square brackets.
Try this sample:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, Forms, Controls, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
  end;

  TMyType = (a, b, c , d);
  TMyTypes = set of TMyType;

const
  SetX:  TMyTypes = [a, b];
  SetY:  TMyTypes = [c, d];
  typeNames: array [TMyType] of string = ('a', 'b', 'c', 'd');

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var SetCombined: TMyTypes;
myType: TMyType;
s: string;
begin
  s := '';
  setCombined :=  SetY + SetX;
  for myType in setCombined do
s := s + typenames[myType];
  ShowMessage(s);
end;

end.

HTH

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


Re: [fpc-pascal] newbie questions

2010-04-19 Thread Howard Page-Clark

On 19/4/10 3:50, spir ☣ wrote:

Hello,

Total Pascal newbie here. Looked for answers in various references and 
tutorials, but cannot find.

Fore-question: Is there a (free)pascal teaching/learning mailing list? (Like python's 
tutor list.) If not, is this one a proper place?

* How does one declare the type of set items?
numbers : Set of Integer// error


type
Tbyteset = set of byte;


* How does one define the _value_ of a Set or Array?
numbers := (1,2,3)  // error
numbers := [1,2,3]  // error


var
byteset : Tbyteset;

begin
byteset := []; // empty set
byteset := [0, 3, 101]; // puts literal values into the set
Include(byteset, 27]; // or byteset := byteset + [27];
Exclude(byteset, 3); // or byteset := byteset - [3];
end;

Note that set types are limited to 256 elements of ordinal types 
(integer, char or enumeration).


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


Re: [fpc-pascal] newbie questions

2010-04-19 Thread Howard Page-Clark



Does this mean that to be able to define a literal value like byteset := [0, 3, 
101]
for a set (and probably for an array) I must have defined a custom 
type for it; correct?
 (It's the only difference I see with my trials: numbers in my code is 
not of a custom type but simply a var of type Set of Integer.)

What I mean is, if the value is a literal, instead of only declaring the var then 
defining its value, one must first make a custom type for it? I don't understand the 
need  purpose of custom types except for records  enums; but this may be 
caused by the fact I come from dynamic languages.



Yes, you have to use the typeName = set of .. type declaration to 
introduce sets.
You can't have a set of integer because that would have more than 256 
elements, and in FP (and Delphi I think) the implementation of sets is 
limited by that storage constraint.
Custom set types are often used in Pascal to enable meaningful names to 
be used for bitmapped values that would otherwise be hard-to-interpret 
numbers. For instance, the styles of the Font class are defined thus:


TFontStyle = (fsBold, fsItalic, fsStrikeOut, fsUnderline);
TFontStyles = set of TFontStyle;

If a font is both bold and italic its Style property will have the 
numerical value 3. However it is difficult to figure out what 3 means 
as a combination of styles. To express it as a combination of named set 
elements fsBold and fsItalic is self-explanatory - the very reason 
most of us prefer Pascal to many other languages.


Drop a TButton on a blank form of a new project. Add typinfo to the uses 
clause, and put this code in the OnClick event of the button.


procedure TForm1.Button1Click(Sender: TObject);
var styleset: TFontStyles;
b: byte absolute styleset;
begin
  if Font.Style = [] then
Font.Style:= Font.Style + [fsBold] + [fsItalic];
  styleset := Font.Style;
 ShowMessage(Format('Font.Style has the value [%s] or, as a numerical 
value %d',
  [SetToString( FindPropInfo(Font, 'style'), integer(Font.Style) ), b ] 
) );

end;

See how the numerical value of Font.Style is not very useful?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Error: Illegal qualifier in converting Delphi unit

2010-03-15 Thread Howard Page-Clark

On 14/3/10 11:52, Frank Church wrote:

Your suggestion worked - what is the secret?
Does the array[0..0 have some relevance here?]

On 14 March 2010 23:01, Howard Page-Clarkh...@talktalk.net  wrote:

On 14/3/10 6:11, Frank Church wrote:


Hi guys,

I am trying to compile the TVersionInfo component by Anders Melander
at http://melander.dk/articles/versioninfo/.

It defines the structure below

type
   TTranslationRec = packed record
 case Integer of
 0: (
   LanguageID: WORD;
   CharsetID: WORD);
 1: (
   TranslationID: DWORD);
   end;
   PTranslationRec = ^TTranslationRec;
   TTranslationTable = array[0..0] of TTranslationRec;
   PTranslationTable = ^TTranslationTable;


which causes the compiler error

VersionInfo.pas(141,37) Error: Illegal qualifier

function TVersionInfo.GetCharset(Index: integer): WORD;
begin
   Result := TranslationTable[Index].CharsetID;
end;

Is there a way to convert for Free Pascal compatibility?


  try:

  result := TranslationTable[Index]^.CharsetID

Howard


No secret - just that fpc requires stricter syntax than Delphi, even in 
{$mode Delphi}. The property TranslationTable is an array property 
declared as a pointer (PTranslationTable), so has to be dereferenced 
before its members can be accessed. It would have helped if the code's 
author had named the property PTranslationTable to highlight that fact, 
because the name hides its pointer character.


H

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


Re: [fpc-pascal] Error: Illegal qualifier in converting Delphi unit

2010-03-14 Thread Howard Page-Clark

On 14/3/10 6:11, Frank Church wrote:

Hi guys,

I am trying to compile the TVersionInfo component by Anders Melander
at http://melander.dk/articles/versioninfo/.

It defines the structure below

type
   TTranslationRec = packed record
 case Integer of
 0: (
   LanguageID: WORD;
   CharsetID: WORD);
 1: (
   TranslationID: DWORD);
   end;
   PTranslationRec = ^TTranslationRec;
   TTranslationTable = array[0..0] of TTranslationRec;
   PTranslationTable = ^TTranslationTable;


which causes the compiler error

VersionInfo.pas(141,37) Error: Illegal qualifier

function TVersionInfo.GetCharset(Index: integer): WORD;
begin
   Result := TranslationTable[Index].CharsetID;
end;

Is there a way to convert for Free Pascal compatibility?


 try:

 result := TranslationTable[Index]^.CharsetID

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


Re: [fpc-pascal] readonly variables

2009-11-28 Thread Howard Page-Clark
On Sat, 28 Nov 2009 15:07:42 +0100
Mattias Gaertner nc-gaert...@netcologne.de wrote:

 On Sat, 28 Nov 2009 14:58:26 +0100
 Jürgen Hestermann juergen.hesterm...@gmx.de wrote:
 
   is it possible to set a variable in a programm as a readonly variable?

 Use the following:
 
 property MyVar: integer read FMyVar write SetMyVar;
 
 And in SetMyVar you can set flag and raise an exception if set for the
 second time.

If the value is known in advance and if no runtime alteration of the
variable is allowed you would of course declare the value as const
rather than var. But this may not fit your case?

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


Re: [fpc-pascal] readonly variables

2009-11-28 Thread Howard Page-Clark
On Sat, 28 Nov 2009 12:10:48 -0500
Anthony Walter sys...@gmail.com wrote:

 procedure InitMyVariable(Value: T);
 function MyVariable: T;
 
 implementation
 
 var
   PrivateMyVariable: T;
   PrivateMyVariableSet: Boolean;
 
 procedure InitMyVariable(Value: T);
 begin
   if not PrivateMyVariableSet then
 PrivateMyVariable := Value;
   PrivateMyVariableSet := True;
 end;
 
 function MyVariable: T;
 begin
   Result := PrivateMyVariable;
 end;

PrivateMyVariableSet is not intialised, so will have an undefined
(random) value when InitMyVariable is first called.
Mattias' code given earlier avoids this problem.

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


Re: [fpc-pascal] Using TFileStream class

2009-03-04 Thread Howard Page-Clark
On Wed, 4 Mar 2009 20:42:14 +0100
Aurélie de LUCA aureliedel...@gmail.com wrote:

 Hy everybody,
 
 I'm trying to use the TFileStream class to read a file with a record,
 and I obtain this message when I execute my application : Access
 violation. You can find my code in the following :
 
 type
 DmatLine= record
   ID1: string;
   ID2: string;
   C: integer;//classe différence 1 if reactions aren't of same
 classe and 0, on the contrary.
   Euclide: double;//Euclidian distance between two reactions.
   Tanimoto: double;//Tanimoto coefficient between two
 reactions. Dice: double;//Dice coefficient between two reactions.
 end;
 
 
 
 procedure TReadDmat.ReadDmat(input: string; nbCpd : integer);
 var
i, j, k, l, m, sizeOfArray, test: integer;
DmatFile: TFileStream;
LineRecord1, LineRecord2: DmatLine;
 begin
  if (FileExists(input) )then
  begin
   DmatFile:=TFileStream.Create(input, fmOpenRead);
   try
  DmatFile.Position := 0;
  while (DmatFile.position  DmatFile.size) {NB ^ see
 above..} do begin
with LineRecord1 do
begin
 DmatFile.Read(ID1, sizeOf(string));
 DmatFile.Read(ID2, sizeOf(string));
(snip)

One problem is your use of long strings in a record structure. Long
strings can be any size, and the size can change at runtime.
Longstring variables are pointers to dynamically allocated storage, so 
Sizeof(string) will always return 4 on 32bit systems.
If DMatLine.ID1 and DmatLine.ID2 are = 255 characters, you could use
shortstrings, declared e. g. as
type
 string40 = string[40];

DmatLine= record
   ID1: string40;
   ID2: string40;
   C: integer;
...
   end;

Then the compiler knows exactly how big each record is, and does the
TFileStream.


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


Re: [fpc-pascal] Re: Using TSdfDataset

2008-09-06 Thread Howard Page-Clark

Felipe Monteiro de Carvalho wrote:

Here is my database file:

ID,NAMEEN,NAMEPT,HEIGHT,WIDTH,PINS,DRAWINGCODE
1,resistor,resistor,1,1,1,LINE
2,capacitor,capacitor,1,1,1,LINE

When listing the value of the NAMEEN field it will show: NAMEEN,
resistor, resistor (yes, resistor again!)

The correct should be: resistor, capacitor


procedure TComponentsDatabase.FillStringListWithNames(AStringList: 
TStrings);

var
 i: Integer;
 CurField: TField;
begin
 AStringList.Clear;

 for i := 1 to FDataset.RecordCount do
 begin
   FDataset.RecNo := i;
   CurField := FDataset.FieldByName(STR_DB_COMPONENTS_NAMEEN);
   AStringList.Add(CurField.Value);
 end;
end;


Try this:

procedure TComponentsDatabase.FillStringListWithNames(AStringList: 
TStrings);

var
 i : Integer;
 CurField: TField;
begin
 AStringList.Clear;
 CurField := FDataset.FieldByName(STR_DB_COMPONENTS_NAMEEN);
 FDataset.First;
 while not FDataset.EOF do
  begin
   AStringList.Add(CurField.Value);
   FDataset.CursorPosChanged;
   FDataset.Next;
  end;
end;

Yours

Howard 


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