Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Sven Barth

On 02.03.2013 03:49, Xiangrong Fang wrote:

Hi there,

If my class constructor looks like this:

constructor TMyClass.Create(fn: string);
begin
   sl := TStringList.Create;
   try
 fs := TFileStream.Create(fn, fmOpenRead);
   except
 self.Destroy;
   end;
end;


No, this is a bad idea. If an exception occurs inside the constructor 
the destructor will be called automatically. I don't even want to think 
about what bad things could happen if you call Destroy inside the 
constructor...



I create the objec like:  MyInstance :=
TMyClass.Create('AnNonExistentFile');  An exception occured, I can
ensure that:

 1. there is no memory leak.


There won't be a memory leak.


 2. the MyInstance variable is assigned *nil*?


If you want to ensure that MyInstance is Nil you need to do it like this:

=== code begin ===

try
  MyInstance := TMyClass.Create('AnNonExistentFile');
except
  MyInstance := Nil;
end;

=== code end ===

Regards,
Sven

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Howard Page-Clark

On 02/03/13 5:45, Flávio Etrusco wrote:

On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang  wrote:

Hi there,

If my class constructor looks like this:

constructor TMyClass.Create(fn: string);
begin
   sl := TStringList.Create;
   try
 fs := TFileStream.Create(fn, fmOpenRead);
   except
 self.Destroy;
   end;
end;

I create the objec like:  MyInstance :=
TMyClass.Create('AnNonExistentFile');  An exception occured, I can ensure
that:

1. there is no memory leak.


I assume FPC behaves like Delphi, so there's no leak.
Actually, you don't even need to explicitly call Destroy; when an
exception occurs in a constructor the destructor is called
automatically.


2. the MyInstance variable is assigned nil?


No, it's not initialized.


But you can write:

constructor TMyClass.Create(fn: string);
var fs: TFileStream;
begin
  sl := TStringList.Create;
  try
fs := TFileStream.Create(fn, fmOpenRead);
  except
self:= nil;
  end;
end;

which gives no memory leak, (provided your destructor frees the 
stringlist sl) and also ensures MyInstance is assigned a nil value.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Michael Van Canneyt



On Sat, 2 Mar 2013, Howard Page-Clark wrote:


On 02/03/13 5:45, Flávio Etrusco wrote:

On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang  wrote:

Hi there,

If my class constructor looks like this:

constructor TMyClass.Create(fn: string);
begin
   sl := TStringList.Create;
   try
 fs := TFileStream.Create(fn, fmOpenRead);
   except
 self.Destroy;
   end;
end;

I create the objec like:  MyInstance :=
TMyClass.Create('AnNonExistentFile');  An exception occured, I can ensure
that:

1. there is no memory leak.


I assume FPC behaves like Delphi, so there's no leak.
Actually, you don't even need to explicitly call Destroy; when an
exception occurs in a constructor the destructor is called
automatically.


2. the MyInstance variable is assigned nil?


No, it's not initialized.


But you can write:

constructor TMyClass.Create(fn: string);
var fs: TFileStream;
begin
 sl := TStringList.Create;
 try
   fs := TFileStream.Create(fn, fmOpenRead);
 except
   self:= nil;
 end;
end;

which gives no memory leak, (provided your destructor frees the stringlist 
sl) and also ensures MyInstance is assigned a nil value.


This will definitely cause a memory leak, because the FPC code does 
not know that an exception occurred in the constructor (you catch it with Except), 
and hence will not call the destructor.


Heap dump by heaptrc unit
27 memory blocks allocated : 2067/2104
25 memory blocks freed : 1947/1984
2 unfreed memory blocks : 120
True heap size : 425984
True free heap : 425568
Should be : 425608
Call trace for block $7FEF86F892C0 size 104
  $0041205C
  $00411D4A
  $00400283 line 15 of tm.pp
  $004004CC line 30 of tm.pp
  $0040018F
Call trace for block $7FEF86F810C0 size 16
  $0041205C
  $004001F7 line 14 of tm.pp
  $004004CC line 30 of tm.pp
  $0040018F

Also, setting Self to nil is nonsense.

If you do FreeAndNil(Self) instead, it will work.

But I would seriously warn against doing this kind of thing.

The idea of exceptions is exactly to let the exception propagate to callers, 
so they know something is wrong. With the code as you propose, 
MyInstance is nil, without any notification whatsoever that something went wrong or what exactly went wrong.


Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Did anybody else use retinizer for Macbook Retina on lazarus before?

2013-03-02 Thread Michael Ring

Hi Mattias,

sorry that I did not answer your Post before today, somehow I did not 
see it.


But as I saw in svn you managed to find it out by yourself, thank you 
for adding retina support to trunk!


Michael

Am 27.02.13 10:59, schrieb Mattias Gaertner:

On Sun, 17 Feb 2013 20:45:07 +0100
Michael Ring  wrote:


The fonts of lazarus look very ugly on my Macbook Retina, a few weeks
ago I found the tool retinizer

http://retinizer.mikelpr.com/

and used it on lazarus, the results were amazing, very nice&crisp fonts!

Nice.
How does it achieve that?
  

I would now like to create the necessary ressources for lazarus so that
it uses retina out of the box without the need of using retinizer, main
problem for me is that I do not use the graphical designer at all, I am
using lazarus for embedded systems only, so I cannot really tell if
switching lazarus to retina mode breaks anything in the GUI.

Anybody else any experience ?


Mattias

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus




--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Howard Page-Clark

On 02/03/13 10:51, Michael Van Canneyt wrote:


This will definitely cause a memory leak, because the FPC code does not
know that an exception occurred in the constructor (you catch it with
Except), and hence will not call the destructor.


Thanks for the correction and explanation.

Howard


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Ok I give up!

2013-03-02 Thread appjaws

Hi,
How do you write the contents of a Memo to a file and read back into a Memo?
I have tried all sorts, I am using Lazarus 1.0.6 on linux.
How this started was because I wanted to write the content of my Memo to 
the clipboard and be able to paste it back in again, but I couldn't 
figure out how to do this in the linux version.
Another thing how can I find out legal qualifiers i.e. Memo.Clear , 
Memo.Text (both illegal). What is legal?

Thank you for any help
Paul
--
---This message has been sent using Thunderbird on kubuntu---

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Reinier Olislagers
On 2-3-2013 13:05, appjaws wrote:
> Hi,
> How do you write the contents of a Memo to a file and read back into a
> Memo?
Memo1.Lines.SaveToFile
Memo1.Lines.LoadFromFile

> Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
> Memo.Text (both illegal). What is legal?
Type Memo. then press ctrl-space, then identifier completion will show
you legal qualifiers.

You can also go to the declaration of the tmemo (using alt-up) and see
the source code to inspect the properties/methods/functions but as
you'll see TMemo descends from TCustomMemo, probably inheriting some
properties etc, and the inheritance tree goes on up.

Finally, built in help is a nice aid: with your cursor on TMemo, press
F1 and you'll see properties and methods that are available.

There are probably more ways...

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Michael Van Canneyt



On Sat, 2 Mar 2013, appjaws wrote:


Hi,
How do you write the contents of a Memo to a file and read back into a Memo?
I have tried all sorts, I am using Lazarus 1.0.6 on linux.


Simple:

Memo1.Lines.SaveToFile('/home/yourname/yourfile.txt');

And

Memo1.Lines.LoadFromFile('/home/yourname/yourfile.txt');


How this started was because I wanted to write the content of my Memo to the 
clipboard and be able to paste it back in again, but I couldn't figure out 
how to do this in the linux version.
Another thing how can I find out legal qualifiers i.e. Memo.Clear , Memo.Text 
(both illegal). What is legal?


Again, simple:

1. use code completion. Type
Memo.
Normally, if you wait ater typing the dot, the list of available qualifiers 
will appear by itself after some time.


2. At least the published qualifiers are visible in the Object Inspector. 
They are accessible in code with exactly the same names.


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Juha Manninen
On Sat, Mar 2, 2013 at 2:05 PM, appjaws  wrote:
> Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
> Memo.Text (both illegal). What is legal?

See Memo.Lines.
It has Clear and Text and everything that TStrings supports.

How to find it? With a new component I usually look at its properties
in Object Inspector, and use the code completion feature of the IDE to
see available methods.
Usually their names are intuitive and self documenting. For example
Memo.Lines is pretty clear.
If I don't find what I wanted then I must read documentation or use Google.

Regards,
Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Hans-Peter Diettrich

Sven Barth schrieb:


If you want to ensure that MyInstance is Nil you need to do it like this:

=== code begin ===

try
  MyInstance := TMyClass.Create('AnNonExistentFile');
except
  MyInstance := Nil;
end;

=== code end ===


When an exception occurs in Create, the assignment will never take 
place. That's why MyInstance should be set to Nil *before* calling the 
constructor. This also applies to memory leak protection of multiple 
temporary objects:


inst1 := nil;
inst2 := nil;
...
try
  inst1 := T1.Create;
  inst2 := T2.Create;
  ...
finally
  inst1.Free;
  inst2.Free;
  ...
end;

The Free does no harm, even if the instances never were created, when 
the variables are nil'ed before the try block.


DoDi


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Hans-Peter Diettrich

Juha Manninen schrieb:

On Sat, Mar 2, 2013 at 2:05 PM, appjaws  wrote:

Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
Memo.Text (both illegal). What is legal?


See Memo.Lines.
It has Clear and Text and everything that TStrings supports.

How to find it? With a new component I usually look at its properties
in Object Inspector, and use the code completion feature of the IDE to
see available methods.
Usually their names are intuitive and self documenting. For example
Memo.Lines is pretty clear.


What is *not* clear, to the OP and many other users, that the required 
functionality is *not* found directly in TMemo, but resides in a 
property (.Lines) of it. In such cases code completion is of little help :-(


DoDi


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Reinier Olislagers
On 2-3-2013 13:54, Hans-Peter Diettrich wrote:
> Juha Manninen schrieb:
>> On Sat, Mar 2, 2013 at 2:05 PM, appjaws  wrote:
>>> Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
>>> Memo.Text (both illegal). What is legal?
>>
>> See Memo.Lines.
>> It has Clear and Text and everything that TStrings supports.
> 
> What is *not* clear, to the OP and many other users, that the required
> functionality is *not* found directly in TMemo, but resides in a
> property (.Lines) of it. In such cases code completion is of little help
> :-(

True, but what other suggestion do you have apart from the ones already
posted?


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Xiangrong Fang
Hi,

Could anyone explain this:

Number := 123;
try
  Number := Ln(0);
except
end;
WriteLn(Number);

The output is *Nan*, not 123. i.e. when exception occurs the variable is
modified anyway!  So in the example below assigning MyInstance to nil
before Create does not help to ensure it is nil if an exception occurs?

Thanks.

2013/3/2 Hans-Peter Diettrich 

> Sven Barth schrieb:
>
>
>  If you want to ensure that MyInstance is Nil you need to do it like this:
>>
>> === code begin ===
>>
>> try
>>   MyInstance := TMyClass.Create('**AnNonExistentFile');
>> except
>>   MyInstance := Nil;
>> end;
>>
>> === code end ===
>>
>
> When an exception occurs in Create, the assignment will never take place.
> That's why MyInstance should be set to Nil *before* calling the
> constructor. This also applies to memory leak protection of multiple
> temporary objects:
>
> inst1 := nil;
> inst2 := nil;
> ...
> try
>   inst1 := T1.Create;
>   inst2 := T2.Create;
>   ...
> finally
>   inst1.Free;
>   inst2.Free;
>   ...
> end;
>
> The Free does no harm, even if the instances never were created, when the
> variables are nil'ed before the try block.
>
> DoDi
>
>
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Michael Van Canneyt



On Sat, 2 Mar 2013, Hans-Peter Diettrich wrote:


Juha Manninen schrieb:

On Sat, Mar 2, 2013 at 2:05 PM, appjaws  wrote:

Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
Memo.Text (both illegal). What is legal?


See Memo.Lines.
It has Clear and Text and everything that TStrings supports.

How to find it? With a new component I usually look at its properties
in Object Inspector, and use the code completion feature of the IDE to
see available methods.
Usually their names are intuitive and self documenting. For example
Memo.Lines is pretty clear.


What is *not* clear, to the OP and many other users, that the required 
functionality is *not* found directly in TMemo, but resides in a property 
(.Lines) of it. In such cases code completion is of little help :-(


You must learn the LCL or VCL.

No amount of IDE help will ever take away that need.

Yes, you must still study. It is inevitable.

Luckily, there is a well-informed community which can provide answers quickly.

As again demonstrated by the answers today.

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Michael Van Canneyt



On Sat, 2 Mar 2013, Xiangrong Fang wrote:


Hi,

Could anyone explain this:

Number := 123;
try
  Number := Ln(0);
except
end;
WriteLn(Number);

The output is Nan, not 123. i.e. when exception occurs the variable is modified 
anyway!  So in the example below assigning MyInstance
to nil before Create does not help to ensure it is nil if an exception occurs?


It does, you can test that.

I suspect that the case above is an artifact of the FPU error reporting, and it 
should be filed as a bug.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Xiangrong Fang
I guess there is really a bug, see the following:
==
  f := 123;
  try
f := ln(0);
  except
  end;
  //WriteLn(f);
  //{
  if f = 123 then
WriteLn('f=123, not modified')
  else
WriteLn('f is modified to:', f);
  //}
===

If I just WriteLn(f), it output Nan, I think there is some magic happening
here.

If I try to use if-then on f, then I get:

An unhandled exception occurred at $0040028C :
EDivByZero : Division by zero
  $0040028C line 18 of project1.lpr


2013/3/2 Michael Van Canneyt 

>
>
> On Sat, 2 Mar 2013, Xiangrong Fang wrote:
>
>  Hi,
>>
>> Could anyone explain this:
>>
>> Number := 123;
>> try
>>   Number := Ln(0);
>> except
>> end;
>> WriteLn(Number);
>>
>> The output is Nan, not 123. i.e. when exception occurs the variable is
>> modified anyway!  So in the example below assigning MyInstance
>> to nil before Create does not help to ensure it is nil if an exception
>> occurs?
>>
>
> It does, you can test that.
>
> I suspect that the case above is an artifact of the FPU error reporting,
> and it should be filed as a bug.
>
> Michael.
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Sven Barth

On 02.03.2013 14:04, Xiangrong Fang wrote:

Hi,

Could anyone explain this:

Number := 123;
try
   Number := Ln(0);
except
end;
WriteLn(Number);

The output is *Nan*, not 123. i.e. when exception occurs the variable is
modified anyway!  So in the example below assigning MyInstance to nil
before Create does not help to ensure it is nil if an exception occurs?


Because there is no exception. If you put a "Writeln" or something into 
the except block you'll see that no exception is raised. Additionally 
the "ln" is a compiler intrinsic. And as you give it a constant 0 the 
compiler will hardcode the "NaN" value instead of calculating it.


The safest way in this case is to put the "Number := 123" into the 
"except" block (though in this specific example it wouldn't change 
anything).


Regards,
Sven

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread Michael Van Canneyt



On Sat, 2 Mar 2013, Sven Barth wrote:


On 02.03.2013 14:04, Xiangrong Fang wrote:

Hi,

Could anyone explain this:

Number := 123;
try
   Number := Ln(0);
except
end;
WriteLn(Number);

The output is *Nan*, not 123. i.e. when exception occurs the variable is
modified anyway!  So in the example below assigning MyInstance to nil
before Create does not help to ensure it is nil if an exception occurs?


Because there is no exception. If you put a "Writeln" or something into the 
except block you'll see that no exception is raised. Additionally the "ln" is 
a compiler intrinsic. And as you give it a constant 0 the compiler will 
hardcode the "NaN" value instead of calculating it.


Hah, I had not thought of this. Indeed, assembler shows you are right :-)

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Juha Manninen
On Sat, Mar 2, 2013 at 2:54 PM, Hans-Peter Diettrich
 wrote:
> What is *not* clear, to the OP and many other users, that the required
> functionality is *not* found directly in TMemo, but resides in a property
> (.Lines) of it. In such cases code completion is of little help :-(

Code completion finds the Lines property without problems.

Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread appjaws

On 02/03/13 12:16, Reinier Olislagers wrote:

On 2-3-2013 13:05, appjaws wrote:

Hi,
How do you write the contents of a Memo to a file and read back into a
Memo?

Memo1.Lines.SaveToFile
Memo1.Lines.LoadFromFile


I tried the following line but I just get an error message :-
Call.pas(87,17) Error: Illegal qualifier

MemoCallNote.Lines.SaveToFile ('/home/paul/tmpinfo/MyTempFile.txt');




Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
Memo.Text (both illegal). What is legal?

Type Memo. then press ctrl-space, then identifier completion will show
you legal qualifiers.


I didn't fine .Lines.SaveToFile?



You can also go to the declaration of the tmemo (using alt-up) and see
the source code to inspect the properties/methods/functions but as
you'll see TMemo descends from TCustomMemo, probably inheriting some
properties etc, and the inheritance tree goes on up.

Finally, built in help is a nice aid: with your cursor on TMemo, press
F1 and you'll see properties and methods that are available.


I don't think my built in help is working, F1 does nothing.
How do I enable built in help?

Thank you to all who responded
Paul

--
---This message has been sent using Thunderbird on kubuntu---

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Reinier Olislagers
On 2-3-2013 14:49, appjaws wrote:
> On 02/03/13 12:16, Reinier Olislagers wrote:
>> On 2-3-2013 13:05, appjaws wrote:
>>> Hi,
>>> How do you write the contents of a Memo to a file and read back into a
>>> Memo?
>> Memo1.Lines.SaveToFile
>> Memo1.Lines.LoadFromFile
> 
> I tried the following line but I just get an error message :-
> Call.pas(87,17) Error: Illegal qualifier
> 
> MemoCallNote.Lines.SaveToFile ('/home/paul/tmpinfo/MyTempFile.txt');
So is MemoCallNote a TMemo? What text is exactly at line 87, position 17?

If I drop a memo and a button on a form and assign this to the button's
OnClick event:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.SaveToFile('d:\cop\t\test.txt');
end;
... it works (on my windows machine - you'd obviously have to change the
path on Linux).

>>> Another thing how can I find out legal qualifiers i.e. Memo.Clear ,
>>> Memo.Text (both illegal). What is legal?
>> Type Memo. then press ctrl-space, then identifier completion will show
>> you legal qualifiers.
> 
> I didn't fine .Lines.SaveToFile?
But did you find Lines? After Lines, do the same for .SaveToFile

I'm starting to suspect that what you think is a memo may not actually
be a memo.

If you want to, you can upload your project as a zip somewhere and I'll
have a look...

>> Finally, built in help is a nice aid: with your cursor on TMemo, press
>> F1 and you'll see properties and methods that are available.
> 
> I don't think my built in help is working, F1 does nothing.
What version of Lazarus are you using - post 1.0 should have built in help.

> How do I enable built in help?
http://wiki.lazarus.freepascal.org/Installing_Help_in_the_IDE


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Xiangrong Fang
Hi,

In order to write cross platform programs, shall I use ForceDirectories or
ForceDirectoriesUTF8?  I would like to:

   - Use native charset on the platform (i.e. UTF8 on Linux and whatever
   codepage on Windows)
   - Avoid using AnsiString or the like (as all my programs use string
   type, change them all to AnsiString is scaring and I don't know the
   consequence at all).

Thanks.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Sven Barth

On 02.03.2013 15:12, Xiangrong Fang wrote:

  * Avoid using AnsiString or the like (as all my programs use string
type, change them all to AnsiString is scaring and I don't know the
consequence at all).


Are your programs compiled in either {$mode Delphi} or {$mode 
ObjFPC}{$H+}? If so then "String" = "AnsiString" already... (otherwise 
String is equivalent to ShortString)


Regards,
Sven

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Xiangrong Fang
My program is always in {$mode objfpc}  So string is not a problem, but
shall I use the UTF8 version or not? I remember that Windows is NOT UTF8?

2013/3/2 Sven Barth 

> On 02.03.2013 15:12, Xiangrong Fang wrote:
>
>>   * Avoid using AnsiString or the like (as all my programs use string
>>
>> type, change them all to AnsiString is scaring and I don't know the
>> consequence at all).
>>
>
> Are your programs compiled in either {$mode Delphi} or {$mode
> ObjFPC}{$H+}? If so then "String" = "AnsiString" already... (otherwise
> String is equivalent to ShortString)
>
> Regards,
> Sven
>
> --
> __**_
> Lazarus mailing list
> Lazarus@lists.lazarus.**freepascal.org
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Leonardo M . Ramé
On 2013-03-02 13:49:48 +, appjaws wrote:
> On 02/03/13 12:16, Reinier Olislagers wrote:
> >On 2-3-2013 13:05, appjaws wrote:
> >>Hi,
> >>How do you write the contents of a Memo to a file and read back into a
> >>Memo?
> 
> MemoCallNote.Lines.SaveToFile ('/home/paul/tmpinfo/MyTempFile.txt');
> 

Is there a space between SaveToFile and the opening parentheses?. Try
removing it.


-- 
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Hans-Peter Diettrich

Reinier Olislagers schrieb:


What is *not* clear, to the OP and many other users, that the required
functionality is *not* found directly in TMemo, but resides in a
property (.Lines) of it. In such cases code completion is of little help
:-(


True, but what other suggestion do you have apart from the ones already
posted?


Only the obvious one: add the frequently used TStrings methods also to 
TMemo. Either explicitly or in some more elegant way.


E.g. the IStrings interface could be added to TMemo, implemented by 
Lines. That's the usual workaround for the lack of multiple inheritance, 
which here and in other list based controls would be the intuitive way 
for having both the list and control methods and properties in the class.


DoDi


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Hans-Peter Diettrich

Juha Manninen schrieb:

On Sat, Mar 2, 2013 at 2:54 PM, Hans-Peter Diettrich
 wrote:

What is *not* clear, to the OP and many other users, that the required
functionality is *not* found directly in TMemo, but resides in a property
(.Lines) of it. In such cases code completion is of little help :-(


Code completion finds the Lines property without problems.


How is this helpful in finding the property, which finally implements 
Clear or some other task?


DoDi


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Sven Barth

On 02.03.2013 15:57, Leonardo M. Ramé wrote:

On 2013-03-02 13:49:48 +, appjaws wrote:

On 02/03/13 12:16, Reinier Olislagers wrote:

On 2-3-2013 13:05, appjaws wrote:

Hi,
How do you write the contents of a Memo to a file and read back into a
Memo?


MemoCallNote.Lines.SaveToFile ('/home/paul/tmpinfo/MyTempFile.txt');



Is there a space between SaveToFile and the opening parentheses?. Try
removing it.




This should not make a difference...

Regards,
Sven

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Juha Manninen
On Sat, Mar 2, 2013 at 4:38 PM, Hans-Peter Diettrich
 wrote:
>> Code completion finds the Lines property without problems.
>
> How is this helpful in finding the property, which finally implements Clear
> or some other task?

First you find Lines, then you find Clear. It is very helpful. :)

Your idea of using interface for method delegation is actually good.
It is actually the only elegant way to duplicate those methods on
TMemo.
I like the idea of extending LCL components instead of only imitating
VCL like a monkey ... which brings us to FireMonkey ... Delphi itself
moved to a more modern library design already.

Using interfaces in a library requires proper design and thinking.
Interfaces must be created for core functionality and injected to many
classes. It is certainly doable. Java did it.
Lots of effort is required to do it properly though.


Regards,
Juha

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread appjaws
Any ideas on the built in help, I'm using linux with lazarus 1.0.6 and 
fpc 2.6.0



Finally, built in help is a nice aid: with your cursor on TMemo, press
F1 and you'll see properties and methods that are available.


 I don't think my built in help is working, F1 does nothing.
 How do I enable built in help?

 Thank you to all who responded
 Paul



--
---This message has been sent using Thunderbird on kubuntu---

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread leledumbo
> I don't think my built in help is working, F1 does nothing. 
  How do I enable built in help? 

http://wiki.freepascal.org/Installing_Help_in_the_IDE



--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Ok-I-give-up-tp4029554p4029579.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread leledumbo
> as all my programs use string type, change them all to AnsiString is
scaring and I don't know the consequence at all

Do you access the string's internal structure? Do you write the string to
file directly instead of taking its content? If not, then nothing you have
to worry about. Standard string operations work the same for all string
type.

> My program is always in {$mode objfpc}  So string is not a problem, but
> shall I use the UTF8 version or not? I remember that Windows is NOT UTF8?

Windows supports wide characters, I don't know the encoding but it's likely
UTF-8 is at least in the subset. I suggest using UTF8 all the time.
1: You don't have to worry about it if in the future you need to support
UTF-8 characters
2: It does not hurt your current program




--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-ForceDirectoriesUTF8-tp4029570p4029580.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Help with... help!

2013-03-02 Thread waldo kitty

On 3/2/2013 00:20, Reinier Olislagers wrote:

Guys,

Anybody else interested in getting F1 to show the offline help if
context-sensitive help is not appropriate?


i followed a wiki page that the help points to... the only thing i'm not sure of 
is why it doesn't get built automatically when i update from SVN and build... 
i'll be working on something and then hit the F1 key and realize that the help 
stuff is being built... weird...



I've gotten partway there but need some help:
http://bugs.freepascal.org/view.php?id=23411


or... maybe i've misunderstood your goal above?


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Martin

On 02/03/2013 13:49, appjaws wrote:

On 02/03/13 12:16, Reinier Olislagers wrote:

On 2-3-2013 13:05, appjaws wrote:

Hi,
How do you write the contents of a Memo to a file and read back into a
Memo?

Memo1.Lines.SaveToFile
Memo1.Lines.LoadFromFile


I tried the following line but I just get an error message :-
Call.pas(87,17) Error: Illegal qualifier

MemoCallNote.Lines.SaveToFile ('/home/paul/tmpinfo/MyTempFile.txt');


"MemoCallNote.Lines" is a TMemo on your form ( TForm1 )?

The above line of code is in a function or procedure that BELONGS to 
TForm1 ?


That is a function or procedure like this
procedure TForm1.somename;
?

If it is in a function or procedure that does NOT have the name of 
TForm1 in it, then it will not work.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread waldo kitty

On 3/2/2013 07:54, Hans-Peter Diettrich wrote:

What is *not* clear, to the OP and many other users, that the required
functionality is *not* found directly in TMemo, but resides in a property
(.Lines) of it. In such cases code completion is of little help :-(


this is what i was going to write but you said it better than i could have... 
this has been the biggest problem i've faced in trying to move to this 
environment as well as learning the new routines and capabilities... it seems 
like every time i start digging about for a way to do something, i find that 
another of my self-built library tools i've used for years is already 
included... it seems that the more i dig, the less i need my own tools...


but back to the above, yes... i wanted to do something similar as the OP, too... 
you'd think that memo.savetofile and memo.loadfromfile would be a natural thing 
and it would automatically do what needed to be done...


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Reinier Olislagers
Hi Paul,

I'm going to respond to the list as well so they know what's going on.

On 2-3-2013 17:35, Paul wrote:
> Thank you  Reinier for your offer to look at my code.I am new to Lazarus
> and am working through some delphi books to try and learn, but this has
> got me stumped.
> I tried a new form with Memo1 and used your code and it worked and the
> file was written to.


Normally it would be easier to send/upload both the .lfm and the .pas
file for the form - or better the entire project (easy via
project/publish project, then zip up the result - then you only include
relevant source files)

Also, saying what Lazarus version you're using normally helps...

That said, look at e.g.:
procedure TmpCut;
begin
  MemoCallNote.Lines.SaveToFile(MyTempFile);
  MemoCallNote.Clear;
end;

This is a regular procedure, not part of your form (the TFormCall object).
Without further changes, this code knows nothing about TFormCall,
including its MemoCallNote object. That's where the invalid qualifier
problems come from.

The easiest way to fix this is to move TmpCut to the private part of the
form:
interface
...
type

  { TFormCall }
  TFormCall = class(TForm)
...
  private
{ private declarations }
procedure TmpCut;
...
this declares a procedure TmpCut as part of the form... and it has
access to form properties etc.

However, you'll need to modify the procedure body from
procedure TmpCut;
to
procedure TFormCall.TmpCut;
to match the declaration above.

Note: all of this typed by hand, hope I did it ok.

Hope this is clear & it works for you.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Help with... help!

2013-03-02 Thread Reinier Olislagers
On 2-3-2013 17:51, waldo kitty wrote:
> On 3/2/2013 00:20, Reinier Olislagers wrote:
>> Guys,
>>
>> Anybody else interested in getting F1 to show the offline help if
>> context-sensitive help is not appropriate?
> 
> i followed a wiki page that the help points to... the only thing i'm not
> sure of is why it doesn't get built automatically when i update from SVN
> and build... i'll be working on something and then hit the F1 key and
> realize that the help stuff is being built... weird...

The only thing that is built once is the lhelp executable. Having lhelp
built when doing a make all or a lazbuild bigide would make sense IMO,
yes, but is different from the issue I linked to.

fpcup builds it for you ;)...

... but if you're using shell/batch scripts it's easy enough to do so, too.

>> I've gotten partway there but need some help:
>> http://bugs.freepascal.org/view.php?id=23411
> 
> or... maybe i've misunderstood your goal above?

I think so, yes. I'm interested in getting a menu item that shows Help
(not just Online Help) and having an F1 press result in getting lhelp
with the table of contents/index/whatever up so a user can peruse the
help - unless he's pressing F1 on an identifier, in which the current
context-sensitive help can pop up as usual.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Reinier Olislagers
On 2-3-2013 17:41, appjaws wrote:
> Any ideas on the built in help, I'm using linux with lazarus 1.0.6 and
> fpc 2.6.0
> 
>>> Finally, built in help is a nice aid: with your cursor on TMemo, press
>>> F1 and you'll see properties and methods that are available.
> 
>  I don't think my built in help is working, F1 does nothing.
>  How do I enable built in help?

Well, did you read the wiki article I posted the link for? What happened?


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread appjaws

On 02/03/13 17:21, Reinier Olislagers wrote:

On 2-3-2013 17:41, appjaws wrote:

Any ideas on the built in help, I'm using linux with lazarus 1.0.6 and
fpc 2.6.0


Finally, built in help is a nice aid: with your cursor on TMemo, press
F1 and you'll see properties and methods that are available.


  I don't think my built in help is working, F1 does nothing.
  How do I enable built in help?


Well, did you read the wiki article I posted the link for? What happened?


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Yes thank you I will have a go tomorrow.
Paul
--
---This message has been sent using Thunderbird on kubuntu---

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread waldo kitty

On 3/2/2013 08:25, Xiangrong Fang wrote:

I guess there is really a bug, see the following:
==
   f := 123;
   try
 f := ln(0);
   except
   end;
   //WriteLn(f);
   //{
   if f = 123 then
 WriteLn('f=123, not modified')
   else
 WriteLn('f is modified to:', f);
   //}
===

If I just WriteLn(f), it output Nan, I think there is some magic happening here.

If I try to use if-then on f, then I get:

An unhandled exception occurred at $0040028C :
EDivByZero : Division by zero
   $0040028C line 18 of project1.lpr


i am unable to reproduce this...

Lazarus 1.1 r39940 FPC 2.6.0 i386-win32-win32/win64


i started a new Simple Program project and pasted your above code into it...

C:\Documents and Settings\nil>LOCALS~1\Temp\project1
f=123, not modified


program Project1;

var
  f : extended;

begin
  f := 123;
try
  f := ln(0);
except
end;
//WriteLn(f);
//{
if f = 123 then
  WriteLn('f=123, not modified')
else
  WriteLn('f is modified to:', f);
//}
end.


so i started a new Program project and again...

C:\Documents and Settings\nil>LOCALS~1\Temp\project1
f=123, not modified


program Project1;

{$mode objfpc}{$H+}

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

var
  f : extended;

begin
  f := 123;
try
  f := ln(0);
except
end;
//WriteLn(f);
//{
if f = 123 then
  WriteLn('f=123, not modified')
else
  WriteLn('f is modified to:', f);
//}
end.


what am i missing??

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread patspiper

On 02/03/13 19:34, waldo kitty wrote:

On 3/2/2013 08:25, Xiangrong Fang wrote:

I guess there is really a bug, see the following:
==
   f := 123;
   try
 f := ln(0);
   except
   end;
   //WriteLn(f);
   //{
   if f = 123 then
 WriteLn('f=123, not modified')
   else
 WriteLn('f is modified to:', f);
   //}
===

If I just WriteLn(f), it output Nan, I think there is some magic 
happening here.


If I try to use if-then on f, then I get:

An unhandled exception occurred at $0040028C :
EDivByZero : Division by zero
   $0040028C line 18 of project1.lpr


i am unable to reproduce this...

Lazarus 1.1 r39940 FPC 2.6.0 i386-win32-win32/win64


i started a new Simple Program project and pasted your above code into 
it...


C:\Documents and Settings\nil>LOCALS~1\Temp\project1
f=123, not modified


program Project1;

var
  f : extended;

begin
  f := 123;
try
  f := ln(0);
except
end;
//WriteLn(f);
//{
if f = 123 then
  WriteLn('f=123, not modified')
else
  WriteLn('f is modified to:', f);
//}
end.


so i started a new Program project and again...

C:\Documents and Settings\nil>LOCALS~1\Temp\project1
f=123, not modified


program Project1;

{$mode objfpc}{$H+}

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

var
  f : extended;

begin
  f := 123;
try
  f := ln(0);
except
end;
//WriteLn(f);
//{
if f = 123 then
  WriteLn('f=123, not modified')
else
  WriteLn('f is modified to:', f);
//}
end.


what am i missing??
Probably 
http://wiki.freepascal.org/Multiplatform_Programming_Guide#Gtk2_and_masking_FPU_exceptions


Stephano

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread waldo kitty

On 3/2/2013 12:43, patspiper wrote:

On 02/03/13 19:34, waldo kitty wrote:

what am i missing??

Probably
http://wiki.freepascal.org/Multiplatform_Programming_Guide#Gtk2_and_masking_FPU_exceptions


the main thing i see there is that the sample uses the math unit... if this is 
what is necessary, then there is definitely some information missing from the 
problem description ;)


i shall test again by adding the math unit to those two test projects...

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Assignment on exception (was Re: exception handling in constructor)

2013-03-02 Thread waldo kitty

On 3/2/2013 12:48, waldo kitty wrote:

On 3/2/2013 12:43, patspiper wrote:

On 02/03/13 19:34, waldo kitty wrote:

what am i missing??

Probably
http://wiki.freepascal.org/Multiplatform_Programming_Guide#Gtk2_and_masking_FPU_exceptions



the main thing i see there is that the sample uses the math unit... if this is
what is necessary, then there is definitely some information missing from the
problem description ;)

i shall test again by adding the math unit to those two test projects...


never mind... my eyes were glazed and i didn't catch the widgetset reference to 
GTK2... after i had hit send on my previous, it struck me what you were actually 
pointing to and i had a much closer read... definitely some info missing from 
the original report :?



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Photo camera and RFID devices

2013-03-02 Thread Arí Ricardo Ody
I was waiting some code examples. I have no expertise in these tecnologies you 
mentioned. SetCommDCB? DirectX?

I have devices with camera and RFID readers builtin, and they aren't exactly 
the most recent models. From which SDK are you talking about? Every device with 
camera and/or RFID reader get these SDKs together? Are they prepared to 
generate pascal code?

Excuse me if i don't have the very advanced knowledge you was expecting. But it 
seems to me that forums have people with various levels of expertise.

Cheers

Ricardo
- Original Message -
From: Anton Kavalenka
Sent: 02/28/13 04:25 PM
To: lazarus@lists.lazarus.freepascal.org
Subject: Re: [Lazarus] Photo camera and RFID devices

On 28.02.2013 21:27, "Arí Ricardo Ody" wrote:
I have a program used for fixed assets field inventory. It runs in handhelds 
running windows mobile with ARM processors.

I would like to know if someone here have used photo cameras and RFID 
readers/receivers in similar equipments. If affirmative should you explain how 
get access(and control) of the camera and the RFID reader/receiver, please?

Greetings from São Paulo - Brazil

Ricardo
Dear Ricardo!

WinCE is a windows from many points of view.

So RFID reader - via serial port CreateFile() > SetCommDCB -> ReadFile 
->Writefile -> Closehandle
Camera - via DirectX

IMO the control inteface with examples have to be expalined in your RFID-reader 
and Camera SDK.

regards,
Anton Kavalenka
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Accessing windows mobile handhelds from Lazarus programs

2013-03-02 Thread Arí Ricardo Ody
Some time a guy from the Lazarus team commented with me that I can use 
microsoft .NET DLLs from a Lazarus program. The idea I have is access SQLite 
databases recorded in a windows mobile handheld from a Lazarus program running 
in a PC computer. I know this is possible when try from a C# program. You can 
read/write SQLite databases direct in the handheld memory.

I would like to know if someone here would have a pratical example of the code 
needed.

Thanks in advance

Greetingsfrom São Paulo - Brazil

Ricardo
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Mark Morgan Lloyd

appjaws wrote:

On 02/03/13 17:21, Reinier Olislagers wrote:

On 2-3-2013 17:41, appjaws wrote:

Any ideas on the built in help, I'm using linux with lazarus 1.0.6 and
fpc 2.6.0


Finally, built in help is a nice aid: with your cursor on TMemo, press
F1 and you'll see properties and methods that are available.


  I don't think my built in help is working, F1 does nothing.
  How do I enable built in help?


Well, did you read the wiki article I posted the link for? What happened?



Yes thank you I will have a go tomorrow.
Paul


Note that if you download the helpfiles manually, you might have to be 
careful of exactly where you put them: it's easy to have a situation 
you've unpacked them in a slightly different directory from where lhelp 
expects.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] exception handling in constructor

2013-03-02 Thread Flávio Etrusco
On Sat, Mar 2, 2013 at 7:51 AM, Michael Van Canneyt
 wrote:
>
>
> On Sat, 2 Mar 2013, Howard Page-Clark wrote:
>
>> On 02/03/13 5:45, Flávio Etrusco wrote:
>>>
>>> On Fri, Mar 1, 2013 at 11:49 PM, Xiangrong Fang  wrote:

(...)
>
> Also, setting Self to nil is nonsense.
>
> If you do FreeAndNil(Self) instead, it will work.
>
> But I would seriously warn against doing this kind of thing.


Wow, this is unexpected. I always thougth that by definition a
constructor would never return nil - so Self was a "by-value"
parameter, even inside a constructor.
Is this by design?
I never saw the point of allowing assign to Self,...

-Flávio

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Maintainers: packages without description: please add them

2013-03-02 Thread Jesus Reyes


--- El vie 1-mar-13, Reinier Olislagers  escribió:

> 
> lazreportpdfexport
> Enables PDF export for lazreport (requires LazReport and
> PowerPDF)
> 
> lr_add_function
> ?
> Additional functions for lazreport (requires LazReport)
> 
> lr_codereport_pkg
> ?
> 
> lr_dialogdesign
> ?
> 
> lr_sqldb
> ?
> 
> lr_tdbf
> DBF database access component for lazreport (requires
> LazReport)
> 
> lr_zeosdb
> Zeos database access component for lazreport (requires
> LazReport)
> 

Updated description on LazReport addon packages in r40462

Jesus Reyes A.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread Flávio Etrusco
On Sat, Mar 2, 2013 at 11:36 AM, Hans-Peter Diettrich
 wrote:
> Reinier Olislagers schrieb:
>
>
>>> What is *not* clear, to the OP and many other users, that the required
>>> functionality is *not* found directly in TMemo, but resides in a
>>> property (.Lines) of it. In such cases code completion is of little help
>>> :-(
>>
>>
>> True, but what other suggestion do you have apart from the ones already
>> posted?
>
>
> Only the obvious one: add the frequently used TStrings methods also to
> TMemo. Either explicitly or in some more elegant way.
>
> E.g. the IStrings interface could be added to TMemo, implemented by Lines.
> That's the usual workaround for the lack of multiple inheritance, which here
> and in other list based controls would be the intuitive way for having both
> the list and control methods and properties in the class.
>
> DoDi
>

I might be wrong, but I guess it won't be very long before name
clashes occur and this comfort and discoverability becomes a mess of
confusing and ugly identifiers.
IMO the correct fix, if it's indeed missing, would be documentation
for TMemo wrt common usage.

-Flávio

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Bart
On 3/2/13, Xiangrong Fang  wrote:

> In order to write cross platform programs, shall I use ForceDirectories or
> ForceDirectoriesUTF8?  I would like to:

I would think that that depends on where you get the value for
ForceDirectories(UTF8) from.
If this vale is obtained from any widget (OpenDialog, TEdit, etc.) the
encoding of the value is in UTF-8.
If however you get the value as a commandline parameter, then it is in
system-encoding if you use ParamStr(), but in UTF-8 if you use
ParamStrUTF8().

So you would use:

Path := ParamStr(1);
ForceDirectories(Path);

or

Path := SelectDirectoryDialog1.FileName;
ForceDirectoriesUtf8(Path);

You need to be sure which encoding a string has when you pass it on to
such procedures/functions.

Bart

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Did anybody else use retinizer for Macbook Retina on lazarus before?

2013-03-02 Thread Johannes W. Dietrich


Hi Mattias,

sorry that I did not answer your Post before today, somehow I did not
see it.

But as I saw in svn you managed to find it out by yourself, thank you
for adding retina support to trunk!


Great! Is there any documentation available?

Thank you, Johannes



Michael

Am 27.02.13 10:59, schrieb Mattias Gaertner:

On Sun, 17 Feb 2013 20:45:07 +0100
Michael Ring  wrote:

The fonts of lazarus look very ugly on my Macbook Retina, a few  
weeks

ago I found the tool retinizer

http://retinizer.mikelpr.com/

and used it on lazarus, the results were amazing, very nice&crisp  
fonts!

Nice.
How does it achieve that?

I would now like to create the necessary ressources for lazarus so  
that
it uses retina out of the box without the need of using retinizer,  
main
problem for me is that I do not use the graphical designer at all,  
I am

using lazarus for embedded systems only, so I cannot really tell if
switching lazarus to retina mode breaks anything in the GUI.

Anybody else any experience ?


Mattias




-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
-- --

-- Dr. Johannes W. Dietrich, M.D.
-- Laboratory XU44, Endocrine Research
-- Medical Hospital I, Bergmannsheil University Hospitals
-- Ruhr University of Bochum
-- Buerkle-de-la-Camp-Platz 1, D-44789 Bochum, NRW, Germany
-- Phone: +49:234:302-6400, Fax: +49:234:302-6403
-- eMail: "j.w.dietr...@medical-cybernetics.de"
-- WWW: http://medical-cybernetics.de
-- WWW: http://www.bergmannsheil.de
-- Researcher ID: C-3498-2009
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --  
-- --






--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] ForceDirectoriesUTF8

2013-03-02 Thread Xiangrong Fang
> I would think that that depends on where you get the value for
> ForceDirectories(UTF8) from.
> If this vale is obtained from any widget (OpenDialog, TEdit, etc.) the
> encoding of the value is in UTF-8.
> If however you get the value as a commandline parameter, then it is in
> system-encoding if you use ParamStr(), but in UTF-8 if you use
> ParamStrUTF8().

That's what I guessed, so Instead of using UTF8 version I would use this to
ensure cross platform correctness:

Path := SelectDirectoryDialog1.FileName;
ForceDirectories(UTF8Decode(Path));

Right? Yesterday I found in this post (which triggered me to ask the
question initially):

http://lists.lazarus.freepascal.org/pipermail/lazarus/2012-April/073170.html

Such problems may (should) go away with the new Unicode- and AnsiString
types, where AnsiString contains an Encoding field. Then the conversion
between UTF-8 and the system codepage are done automatically, whenever
required, and the xyUTF8 functions can be dropped then.

If so, we shall avoid using **UTF8 functions at all.


2013/3/3 Bart 

> On 3/2/13, Xiangrong Fang  wrote:
>
> > In order to write cross platform programs, shall I use ForceDirectories
> or
> > ForceDirectoriesUTF8?  I would like to:
>
> I would think that that depends on where you get the value for
> ForceDirectories(UTF8) from.
> If this vale is obtained from any widget (OpenDialog, TEdit, etc.) the
> encoding of the value is in UTF-8.
> If however you get the value as a commandline parameter, then it is in
> system-encoding if you use ParamStr(), but in UTF-8 if you use
> ParamStrUTF8().
>
> So you would use:
>
> Path := ParamStr(1);
> ForceDirectories(Path);
>
> or
>
> Path := SelectDirectoryDialog1.FileName;
> ForceDirectoriesUtf8(Path);
>
> You need to be sure which encoding a string has when you pass it on to
> such procedures/functions.
>
> Bart
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] "buffer" and string

2013-03-02 Thread Xiangrong Fang
Hi,

I encountered unpredictable behavior with the following code:

var
  fs: TFileStream;
  s: string;
begin
  ... ...
  fs.Write(s, Length(s));
  ... ...
end;

But if I do this, then problem is gone:

var
  fs: TFileStream;
  s: string;
  buf: PChar;
begin
  ... ...
  buf := GetMem(Length(s) + 1);
  StrPCopy(buf, s);
  fs.Write(buf^, Length(s));
  ... ...
end;

My question is, why the above code with string works sometime, but not
alwasy fail? What is the internal structure of string and variable array
(i.e. array of something)?  What is the difference between @string and
@string[1] or @array and @array[0]?

Thanks
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Ok I give up!

2013-03-02 Thread waldo kitty

On 3/2/2013 13:20, Mark Morgan Lloyd wrote:

Note that if you download the helpfiles manually, you might have to be careful
of exactly where you put them: it's easy to have a situation you've unpacked
them in a slightly different directory from where lhelp expects.


agreed... and if following the given instructions, things do work but files are 
not where they should apparently be...


by that i mean that chm files are placed in html directory instead of chm 
directory or whatever the instructions call for... it was something i noticed a 
while back but never followed up on...



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] "buffer" and string

2013-03-02 Thread leledumbo
> My question is, why the above code with string works sometime, but not
alwasy fail?

TStream.Write expects a buffer, typically the first element of an item (NOT
a pointer to it) and the length (number of elements after first one).

> fs.Write(s, Length(s));

Here you try to give the WHOLE string, which is variable depending on the
string type. It could be plain array for ShortString, but also pointer to a
dynamically allocated structure for other strings. For ShortStrings,
however, the above code will have the string length (if I'm not mistaken)
before the first character in the written file.

To do it correctly without converting to PChar is to give the first element:

fs.Write(s[1], Length(s));

> What is the internal structure of string and variable array (i.e. array of
> something)?

Explained in docs:
- static array:
http://www.freepascal.org/docs-html/prog/progsu161.html#x204-2170008.2.9
- dynamic array:
http://www.freepascal.org/docs-html/prog/progsu162.html#x205-2180008.2.10
- strings:
http://www.freepascal.org/docs-html/prog/progsu159.html#x202-2120008.2.7

> What is the difference between @string and @string[1] or @array and
> @array[0]?

@string means pointer to to the string STRUCTURE, for ShortString, this is
the same as @string[0] (the length)
@string[1] means pointer to the first character in the string
@array means pointer to the array STRUCTURE, for static array, this is the
same as @array[]
@array[0] means pointer to the element at index 0





--
View this message in context: 
http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-buffer-and-string-tp4029601p4029603.html
Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] "buffer" and string

2013-03-02 Thread Xiangrong Fang
If a buffer expect the first "element", and count is the number of elements
to write, then what is the unit size of that element? is it always "byte"?

2013/3/3 leledumbo 

> > My question is, why the above code with string works sometime, but not
> alwasy fail?
>
> TStream.Write expects a buffer, typically the first element of an item (NOT
> a pointer to it) and the length (number of elements after first one).
>
> > fs.Write(s, Length(s));
>
> Here you try to give the WHOLE string, which is variable depending on the
> string type. It could be plain array for ShortString, but also pointer to a
> dynamically allocated structure for other strings. For ShortStrings,
> however, the above code will have the string length (if I'm not mistaken)
> before the first character in the written file.
>
> To do it correctly without converting to PChar is to give the first
> element:
>
> fs.Write(s[1], Length(s));
>
> > What is the internal structure of string and variable array (i.e. array
> of
> > something)?
>
> Explained in docs:
> - static array:
> http://www.freepascal.org/docs-html/prog/progsu161.html#x204-2170008.2.9
> - dynamic array:
> http://www.freepascal.org/docs-html/prog/progsu162.html#x205-2180008.2.10
> - strings:
> http://www.freepascal.org/docs-html/prog/progsu159.html#x202-2120008.2.7
>
> > What is the difference between @string and @string[1] or @array and
> > @array[0]?
>
> @string means pointer to to the string STRUCTURE, for ShortString, this is
> the same as @string[0] (the length)
> @string[1] means pointer to the first character in the string
> @array means pointer to the array STRUCTURE, for static array, this is the
> same as @array[]
> @array[0] means pointer to the element at index 0
>
>
>
>
>
> --
> View this message in context:
> http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-buffer-and-string-tp4029601p4029603.html
> Sent from the Free Pascal - Lazarus mailing list archive at Nabble.com.
>
> --
> ___
> Lazarus mailing list
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus