Re: [Lazarus] Invalid component names

2009-04-27 Thread dmitry boyarintsev
to be sure about name is unique name at the run time there're at least two ways.

1st) global counter

var
  GlobalCounter : integer = 0;

function GetUniqueName(ClassName: String = ''): string;
begin
  if PrefixName = '' then Result := 'dynamicComponent'+IntToStr(GlobalCounter)
  else Result := Copy(ClassName, 2, length(ClassName)-1) +
IntToStr(GlobalCounter);
  // need to care about thread safety here.
  inc(GlobalCounter);
end;

2nd) use GUIDs.

function GetUniqueName(ClassName: String = ''): string;
var
  g : TGUID;
begin
  SysUtils.CreateGUID(g);
  Result := ClassName + GUIDToString(g);
end;

...

  AComponent := TSomeType.Create( owner );
  AComponent.Name := GetUniqueName(AComponent.ClassName);

thanks,
dmitry
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Invalid component names

2009-04-27 Thread Hans-Peter Diettrich
Mattias Gaertner schrieb:

 So the remaining question is: How to assign unique names to
 dynamically created components? Does there exist an immediately
 usable method or function?

 Empty names seem to be harmless, but every attempt to assign an 
 non-empty and already used name to a component results in an
 exception.

 What's the scope (list of names...), within which every component
 must have an unique name?
 
 Have you looked at TComponent.SetName?

Thanks, that answers the latter question.

Nonetheless there should exist a method, at least in the form designer, 
for creating unique names. Where is it?

DoDi

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


Re: [Lazarus] Invalid component names

2009-04-27 Thread Hans-Peter Diettrich
Gabor Boros schrieb:

 I always use the variable's name to component name.
 
 var
 MyLabel15:TLabel;
 
 begin
 MyLabel15:=TLabel.Create(Self);
 MyLabel15.Name:='MyLabel15';
 end;

Exactly this code will cause an exception, when the procedure is called 
more than once - as I need it to create multiple floating controls.

DoDi

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


Re: [Lazarus] Invalid component names

2009-04-27 Thread Gerard N/A
On Mon, Apr 27, 2009 at 11:14 AM, Hans-Peter Diettrich
drdiettri...@aol.com wrote:
 Nonetheless there should exist a method, at least in the form designer,
 for creating unique names. Where is it?

Have a look at function TCustomFormEditor.CreateUniqueComponentName in
ide\customformeditor.pp

Regards,

Gerard.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Invalid component names

2009-04-27 Thread Vincent Snijders
 Exactly this code will cause an exception, when the procedure is called
  more than once - as I need it to create multiple floating controls.

Why do you want to give the controls names?

Vincent
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Invalid component names

2009-04-27 Thread Hans-Peter Diettrich
Vincent Snijders schrieb:
 Exactly this code will cause an exception, when the procedure is called
  more than once - as I need it to create multiple floating controls.
 
 Why do you want to give the controls names?

Names are convenient to identify floating windows (label title bars) or 
docked controls (dock header label), and are required for the 
de/serialization of docking layouts.

But you are right in so far, as dynamically created controls are of 
little use in the recreation of a docking layout. In this case the names 
should be hardwired somehow, so that the appropriate controls can be 
created from the stored layout. I'll have to re-think this issue in the 
implementation of multiple editor windows and the related forms. Then 
e.g. the code explorer windows etc. must be linked to the edit control 
in their dock site, regardless of their name in creation order.

DoDi

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


Re: [Lazarus] Invalid component names

2009-04-27 Thread Hans-Peter Diettrich
Gerard N/A schrieb:

 Nonetheless there should exist a method, at least in the form designer,
 for creating unique names. Where is it?

 Have a look at function TCustomFormEditor.CreateUniqueComponentName in
 ide\customformeditor.pp

Thanks :-)

DoDi

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


Re: [Lazarus] Invalid component names

2009-04-27 Thread Mattias Gärtner
Zitat von Hans-Peter Diettrich drdiettri...@aol.com:

 Vincent Snijders schrieb:
  Exactly this code will cause an exception, when the procedure is called
   more than once - as I need it to create multiple floating controls.
 
  Why do you want to give the controls names?

 Names are convenient to identify floating windows (label title bars) or
 docked controls (dock header label), and are required for the
 de/serialization of docking layouts.

 But you are right in so far, as dynamically created controls are of
 little use in the recreation of a docking layout. In this case the names
 should be hardwired somehow, so that the appropriate controls can be
 created from the stored layout. I'll have to re-think this issue in the
 implementation of multiple editor windows and the related forms. Then
 e.g. the code explorer windows etc. must be linked to the edit control
 in their dock site, regardless of their name in creation order.

Welcome to the complex world of layout restoration. ;)

Just an idea:
The anchor docking manager has one component per docked control. It allows to
set a unique name and will use by default the component name. The manager will
resolve conflicts by appending a number. The user can set the name via the
designer and a translated name for i18n.


Mattias

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


Re: [Lazarus] EXC_BAD_ACCESS, Could not access memory

2009-04-27 Thread dmitry boyarintsev
use:
  TYPE TMyOne = packed record
  First:integer;
  Second:extended;
END;
to be sure about 20 bytes boundary.

thanks,
dmitry
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] EXC_BAD_ACCESS, Could not access memory

2009-04-27 Thread Bogusław Brandys
Roland Turcan wrote:
 Hello All,
 
 I have found some new information about this problem:
 
 1.
 
 TYPE TMyOne =record
First:integer;
Second:integer;
  end;
 
 ... then the size of this object is 2*4 bytes.
 
 2.
 
 TYPE TMyOne =record
First:integer;
Second:double;
  END;
 
 ... where I would expect 4 + 8 bytes = 12 bytes
 ... but the size of this object is 16!
 
 
 3.
 
 TYPE TMyOne =record
First:integer;
Second:extended;
  END;
 
 ... where I would expect 4 + 16 bytes = 20 bytes
 ... but the size of this object is 32!
 
 
 So this proves me, that compiler tries to align the data structure to
 multiplied size of biggest element to which fit all elements.
 
 I have understood this behavior, but this happens me in these cases:
 
 1. Delphi 7
 2. Kylix 3
 3. Lazarus on Ubuntu
 4. Lazarus on PowerPC Mac OS X 10.5
 
 but on Intel Based Mac OS X 10.5 Mini with Intel Duo 2 Core it
 DOESN'T. Therefore I have problems with parsing of binaries back to
 memory.
 
 I don't expect CPU specific problem, otherwise it would not work
 active projects, therefore I think it must be compiler specific
 problem.
 
 Do you have any idea?
 
 Thanks in advance.
 
 Greetings, TRoland;

Have you checked packed records ?


Boguslaw
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] EXC_BAD_ACCESS, Could not access memory

2009-04-27 Thread Bart
I'm not even sure that Extended has the same size on all platforms.
I might of course be horribly wrong about this ;-)
But if not, it might complicate things.

If you need to read those records, created with Delphi/Kylix now on
MacOS and you cannot solve how to declare your record, you could as a
last resort read x bytes (where x is the size of the delphi record on
disk) and translate theis sequence of bytes to the values you want.

It's just one of those things with proprietary formats and cross-platform usage.

Bart
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] EXC_BAD_ACCESS, Could not access memory

2009-04-27 Thread Mattias Gaertner
On Mon, 27 Apr 2009 17:27:30 +0200
Roland Turcan k...@rotursoft.sk wrote:

 Hello Dmitry,
 
 Thanks for your reply, but I think, that you haven't understood me
 what I am trying to explain.
 
 I have binary contents which are copied from memory using by an
 application which is written in Delphi. I am porting an application to
 MacOS X 10.5, but I need to use the same structures as I have in
 Delphi and Kylix where NOT PACKED records are aligned.
 
 The fact is, that FPC compiler on intel based Mac OS X builds up
 application which contains records packed by 4 bytes by default.

Use packed records and add gap variables.

 
 I need to get the same behavior in intel based mac os x as I have in
 other platforms.
 
 What should I do to build FPC compiler which will behave the same on
 all platforms.

This won't work. The other sources and libs expect another alignment.
FPC uses the various alignments for good reason.


Mattias
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] EXC_BAD_ACCESS, Could not access memory

2009-04-27 Thread Hans-Peter Diettrich
Bart schrieb:

 I'm not even sure that Extended has the same size on all platforms.

What size might it have, other than the FPU defined size?


 If you need to read those records, created with Delphi/Kylix now on
 MacOS and you cannot solve how to declare your record, you could as a
 last resort read x bytes (where x is the size of the delphi record on
 disk) and translate theis sequence of bytes to the values you want.

If nothing else helps, it should be sufficient to use packed records 
with inserted dummy fields for the original record layout.

DoDi

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