Re: [fpc-pascal] Persistent blocks in Lazarus

2009-07-21 Thread Martin Friebe

[cross-posted to lazarus list = please join there to continue the topic]

I am trying to figure out how they work

- Block is kept, if cursor moves away. (obvious)
- Shift Cursur keys:
 - Block is extended if cursor was next to block
 - New block is started , if cursor was away from block.
(could also be used to extend the block, like shift-left-mouse)
- Block is kept, position/size adjusted if text is typed before, or into 
the block  (exception, column mode block is not adapted)

- ctrl-c copies the block, at any time

annoyances I found in turbo explorer (the free delphi), not sure if they 
are supposed to be.

- Move the caret via mouse (left click) = block is undone
- paste/ctrl-v : the newly inserted text is selected as new block?
  (this means the current block is lost)

That's all the knowledge I have about them sofar.

Anyone wants to update me?

Martin

Andreas Berger wrote:



On Thu, Jul 16, 2009 at 01:36:15PM +0200, Andreas Berger wrote:
 
Out of curiosity (because I never used this feature in any editor), 
what would you use it for?
  
Persistent blocks and the full Wordstar keyboard shortcuts is why I 
use the Delphi IDE until today.



If you miss wordstar stuff, please list it.


Well, maybe I should use the Lazarus IDE again for a bit a jot down 
what I would like. I may even soon have time to help add some options.


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

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


Re: [fpc-pascal] Clipboard tutorial.

2009-07-17 Thread Martin Friebe

If you use Lazarus (or at least the LCL) it has a unit Clipbrd

and you can do
   Clipboard.AsText:= FText;

Martin

Torsten Bonde Christiansen wrote:

Graeme Geldenhuys wrote:

Torsten Bonde Christiansen wrote:


Does anyone know of a page that has a short introduction/tutorial, 
preferably something that will work cross-platform wise.



What GUI toolkit are you using and what platform?  Or is it a console 
based application, which normally means the clipboard only functions 
inside your own application.

GUI application and preferably every possible combination.

I'm creating a cross-platform application that in some part of the 
program should be able to access the clipboard and read data as text 
only.


But from your answer if guess there is no single (simple) way to do this?

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

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


Re: [fpc-pascal] Persistent blocks in Lazarus

2009-07-17 Thread Martin Friebe
We are still on the wrong mailing list. Should be 
laza...@lists.lazarus.freepascal.org


Anyway, if it's about SynEdit, feel free to ask where to start looking, 
I am glad to give some pointers. (But please make sure you are on SVN 
0.9.27, since it is completely different)


From What I understand, there are 2 issues:
- the missing persistent block
I don't even know how many persistent-block related commands there are. 
IIRC from never mind hom many years ago, you have to Key-Shortcuts, to 
set it's end and begin? (Instead of using shift-cursor?)

What other commands are there?
It may be possible to break it down into the most needed (set-begin, 
set-end, copy, move) commands, and otheres that can be added over time?


- The Keyboard layout/scheme for wordstar ?
How different is that from current default, or classic-scheme default?

Martin


Andreas Berger wrote:



On Thu, Jul 16, 2009 at 01:36:15PM +0200, Andreas Berger wrote:
 
Out of curiosity (because I never used this feature in any editor), 
what would you use it for?
  
Persistent blocks and the full Wordstar keyboard shortcuts is why I 
use the Delphi IDE until today.



If you miss wordstar stuff, please list it.


Well, maybe I should use the Lazarus IDE again for a bit a jot down 
what I would like. I may even soon have time to help add some options.


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

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


Re: [fpc-pascal] Persistent blocks in Lazarus

2009-07-15 Thread Martin Friebe
First of all, Lazarus has it's own mailing list, where you will be more 
likely to receive answers...


Jürgen Hestermann wrote:

A question:

Do persistent blocks exist the Lazarus editor?

Not at current.


If it does not exist, is it planned to add?
Maybe some day. There is no concrete plan that I know of, so it isn't 
likely to be any time soon.

Patches are welcome.

I miss this mode very much. It allowed a way of working which cannot 
be achieved with the current temporary block mode.


Out of curiosity (because I never used this feature in any editor), what 
would you use it for?


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


implicit exception frames? [Re: [fpc-pascal] If an Assert fails in constructor, then destructor called (?)]

2009-07-02 Thread Martin Friebe

Inoussa OUEDRAOGO wrote:

2009/6/29 Tom Verhoeff t.verho...@tue.nl:
  

While tracing a nasty bug (?), I discovered the hard way that when
an Assert is done in a constructor, and it fails, then the destructor
(Destroy) is automatically called.



Indeed, when an exception is raised in the constructor, be it an
assert exception or not, the destructor is called to allow the
developer to clean up the in-construction instance's members he has
already initialized.
  
I just cam across this thread. While I am not opposing the behaviour as 
it's stand (it could be useful anyway), it raises another question.


Does that mean that an implicit exception-frame (or whatever this is 
called) is inserted *each* time you create/instantiate an object?


Now I understand, object instantiation comes at a cost anyway (memory 
allocation), this does add to the cost of instantiation. And the only 
error/exception, which really *all* classes can encounter in a 
constructor, is out of memory for the object itself = In which case 
create is never called (because NewInstance fails), and Destroy should 
not be called (as there is no instance that could be passed to destroy).
So There could be calls to create where a developer does not want (and 
not need) any exception stack frame.


I also wonder why this special kind of garbage collector? Pascal has 
automatic behaviour to handle/free resources for:

- strings
- open array
- apparently classes/objects, but only inside the constructor ?

The last one does of course not apply to objects hold by the failed 
object, but I assume that, if Destroy is called, the instance is also freed?
So why are objects handled special in the constructor? If they raise an 
exception anywhere else in there live, then you need to care yourself 
about catching it, and freeing them?


Anyway, as I said it's not necessarily bad behaviour. but given that 
exception handling may add to runtime cost, is there a way to switch 
this off?

Like
{$AutoDestroty off}
try
  foo := TFoo.create;
except
  if foo  nil then foo.free;
end;



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


Re: implicit exception frames? [Re: [fpc-pascal] If an Assert fails in constructor, then destructor called (?)]

2009-07-02 Thread Martin Friebe

Michael Van Canneyt wrote:

On Thu, 2 Jul 2009, Martin Friebe wrote:

Inoussa OUEDRAOGO wrote:

Indeed, when an exception is raised in the constructor, be it an
assert exception or not, the destructor is called to allow the
developer to clean up the in-construction instance's members he has
already initialized.

I just cam across this thread. While I am not opposing the behaviour 
as it's stand (it could be useful anyway), it raises another question.


Does that mean that an implicit exception-frame (or whatever this is 
called) is inserted *each* time you create/instantiate an object?


Now I understand, object instantiation comes at a cost anyway (memory 
allocation), this does add to the cost of instantiation. And the only 
error/exception, which really *all* classes can encounter in a 
constructor, is out of memory for the object itself = In which case 
create is never called (because NewInstance fails), and Destroy 
should not be called (as there is no instance that could be passed to 
destroy).
So There could be calls to create where a developer does not want 
(and not need) any exception stack frame.


I also wonder why this special kind of garbage collector? Pascal 
has automatic behaviour to handle/free resources for:

- strings
- open array
- apparently classes/objects, but only inside the constructor ?

The last one does of course not apply to objects hold by the failed 
object, but I assume that, if Destroy is called, the instance is also 
freed?
So why are objects handled special in the constructor? If they raise 
an exception anywhere else in there live, then you need to care 
yourself about catching it, and freeing them?


Because you cannot handle it yourself. Assume the following statement:

  MyClass:=TSomeClass.Create;

if an exception happens inside the constructor, then no instance 
pointer is assigned to MyClass, since execution after the exception is 
raised is continued at the next except/finally block.
That means you cannot handle destruction in the except block (assuming 
you

wrote one) since you have no pointer to work with.

Therefor the constructor code must call the destructor in case of an 
error.
Yes, of course, you are right. It is impossible to handle it in the 
calling code. As the order is:

- instantiation (NewInstance)
- Create
 - exception
- assignment to local var = never executed

But you can handle it yourself inside the constructor.
No one stops the developper from wrtiting

Constructor TFoo.Create;
begin
 try
  ...
 except
   self.Destroy; // Or Free ?
 end;
end;


- If an error/exception (out of mem) happens in NewInstance, neither 
Create nor Destroy are called (and neither can they be called, because 
they need an (empty) instance and there is none)
- If an error in Create happens, self is assigned (inside Create). So it 
can be acted on.
Even if, in the above example, this Create was called by a child-class 
via inherited Create. There is no worry (not even if self.Free is used), 
that the inherited constructor will find an invalid pointer in self 
(because/if it has been freed). The code above, never returns to the 
inherited constructor, unless this inherited constructor itself catches 
the exception too (in which case it must check ; It would need to be 
flagged on the exception object)


Anyway, while possible, it would be far to complicated. So I agree, the 
automated handling, ensuring the instance is Destroyed and freed once 
only, is probably the best



Leaves question 2: Is there a way to switch it off, to avoid the cost of 
creating an exception frame? (if you are either sure your constructor 
does not throw an exception, or for some reason do not care)?



Thanks for the explanation so far
Martin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: implicit exception frames? [Re: [fpc-pascal] If an Assert fails in constructor, then destructor called (?)]

2009-07-02 Thread Martin Friebe

Jonas Maebe wrote:

On 02 Jul 2009, at 16:58, Martin Friebe wrote:
Leaves question 2: Is there a way to switch it off, to avoid the cost 
of creating an exception frame? (if you are either sure your 
constructor does not throw an exception, or for some reason do not 
care)?


http://www.freepascal.org/docs-html/prog/progsu32.html

It also applies to the exception frames in constructors.


thanks a lot
Martin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Writeable typed constants - what's the point?

2009-06-19 Thread Martin Friebe

Jürgen Hestermann wrote:



 Paul Nicholls schrieb:
I also find writable constants hand for things like this where I can 
define the 'variable' + values too so I don't have to set the values 
at run time:


But can't you do the same with a variable declaration? If you want to 
change the value at runtime it's definitely not a constant anymore.

Not always


Beeing able to change a typed constant was added by Borland as a 
quick hack (because constants were put into the global data segement 
even in function declarations) but actually its semantic is wrong. If 
you can change it, it has to be a variable declaration and you should 
not be able to change a constant.

there is an important difference between
const a: word = 1;
const a = word(1); // never writeable
var a: word = 1;

The1 1st and 3rd are (afaik) the same, if used top level, that is in the 
global context of interface, or implementation

.

But if
procedure Foo;
 const a: word = 1;
 var a: word = 1;
begin
end;

Then they are 2 difference things.

The var version, acts as if your first statement in the procedure was 
a:= 1;. It initializes the variable each time you enter the function. 
If you enter the function recursively, then each level, has it's own a, 
not touching the value of the callers a


The const version act like a global variable. It is set to 1 once at 
some time before the 1st call to Foo. It will not be initialized again. 
If Foo chages it, it will keep the changed value, even between calls to 
Foo. If Foo enters recursively, it act like a global var, there is only 
one a, shared by all calls to Foo.
If Foo is a Method on an object, then it is shared between all instances 
of the object.
The only difference to a global var is, that no one outside Foo can see 
or access it.


And you can't do that with an initialized var. And there are plenty of 
use-cases for it.


Martin




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


Re: [fpc-pascal] Writeable typed constants - what's the point?

2009-06-18 Thread Martin Friebe

Graeme Geldenhuys wrote:
FPC often implements something that breaks existing code. 
  

Examples :)?




Please note that I am not saying I disagree with the changes. I know
they were introduced for the better. What I am saying, is that changes
do get introduced into FPC (for whatever reason) and does sometimes
break existing code.

Example #1:
  You cannot pass a property as var parameter anymore. Introduced in
  v2.2.0

Example #2:
  Boolean type change in Xlib units. TBool(false) or TBool(true) type
  usage.

Example #3:
  ComponentState change. I wasn't allowed to use the following code
  anymore:  Include(ComponentState, csDesigning);


I think there was a few more that affected fpGUI Toolkit project, but I
think you get the idea. As long as code is being maintained, such
changes are not the end of the world. :-)  But my point is, they do happen!

  


Afaik 1  3 are the same?

And if I understand the changes where mad, because this feature was 
broken before:
That is the syntax you mentioned lead to an unpredictable result, and 
the circumstances under which it did what you wanted could change 
outside your code and without the intend to make them change.


Or in other words: This only worked if a property directly read a 
variable, but not if it was a function result = meaning you had 2 
different types of properties. But only one was documented.


Best Regards
Martin


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


Re: [fpc-pascal] Generic a Clone method

2009-06-16 Thread Martin Friebe

Torsten Bonde Christiansen wrote:

Hi.

I was wondering if it is posible to make this type of construct for 
creating a generic Clone method:


(I put it in pastebin):  http://pastebin.com/fb495ed7

Explained in words - I'm trying to make a clone method that should be 
able to copy the content of private variables to a destination object.
Naturally this destination would have to be of the same class as the 
original, but is it posible to determine the size of used space in 
each derived class, simply by using Sizeof(...). Or do I need to 
create a seperate clone method for each individual derived class.


If it is posible, what memory copy function should I use?


There is Object.InstanceSize, which sounds as if it may be what you are 
looking for.

But you have a bigger problem than that.

If any member (object variable) is of a ref-counted type (that is 
strings and dynamic arrays), then any memory copy will mess up.


Because in the objects memory, there only are the pointers to the data 
of strings, and dyn-arrays. If you copy those pointer by hand, then the 
reference-counts in the actual string or dyn-array are not updated.

this leads to at least 2 problems.

1)
If the original object was the only holder (or last remaining) of a 
reference to this string, and your original or new object is destroyed, 
the ref-count goes down to zero = the string is freed, and the other 
object points to unallocated memory, or meory allocated to some 
new/other data) = crash


2)
Again if, your old object was the only holder, then the ref-count is 
still 1. Strings are copy on modify, = 2 copies of a string share 
memory until one is changed (in which case a copy is made). The need for 
making the copy is determined by ref-count  1.
Your ref-count is 1 = no copy is made, the new object is updating the 
strings of the old object too


Best Regards
Martin



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


Re: [fpc-pascal] Generic a Clone method

2009-06-16 Thread Martin Friebe



Torsten Bonde Christiansen wrote:

Martin Friebe wrote:


If any member (object variable) is of a ref-counted type (that is 
strings and dynamic arrays), then any memory copy will mess up.


Because in the objects memory, there only are the pointers to the 
data of strings, and dyn-arrays. If you copy those pointer by hand, 
then the reference-counts in the actual string or dyn-array are not 
updated.

this leads to at least 2 problems.

1)
If the original object was the only holder (or last remaining) of a 
reference to this string, and your original or new object is 
destroyed, the ref-count goes down to zero = the string is freed, 
and the other object points to unallocated memory, or meory allocated 
to some new/other data) = crash


2)
Again if, your old object was the only holder, then the ref-count is 
still 1. Strings are copy on modify, = 2 copies of a string share 
memory until one is changed (in which case a copy is made). The need 
for making the copy is determined by ref-count  1.

Can this be avoided by using the UniqueString(..)  method?


If you know where the strings are...; but then it's no longer unique.

You can try something else, but i have no idea where it leads too, or if 
its usable (in objpas mode)


type
TFoo = object
private
public
end;

Acts like a record, with methods, kind of.

anyway
 var a, b: TFoo

 a:=b;

Takes care of everything.

BUT those objects are like records. they do not allocate ne meory, 
each time you create them, they alloc mem when you *declare* them


if you pass them to a function in the arg list, they get copied. ( with 
class the pointer gets copied, because class is in reality a pointer.


 So you could declare
TRealFoo = ^TFoo;

then write your constructor to return the pointer,
every access would need the dereference of course = massive change to 
syntax.


and so on.
If it is for you, you have to RT(F)M yourself



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


Re: [fpc-pascal] A complex trouble(at least for me)

2009-05-08 Thread Martin Friebe

Arí Ricardo Ody wrote:

Suppose the following structure:

01 a-1.
   03 b-1 pic xxx.
   03 b-2 pic 999.
   03 b-3.
  05 c-1 pic aaa.
  05 c-2.
 07 d-1 pic zzz.
 07 d-2 pic xxx.
  05 c-3 pic 99.
   03 b-4 pic zzz.
   03 b-5.
  05 e-1 pic zzz.

All line not containing the word pic I would call a group item and the 
other lines will be elementary items.


I would like to wrote a routine(or program) that save each group item 
and the elementary items contained in a StringList. Admit that the 
pattern of the structure is random. The example above is only an example.


In this example:
StringList1 will contain 'a-1' '03 b-1 pic xxx.' '03 b-2 pic 999.' '03 
b-4 pic zzz.'

StringList2 will contain 'b-3' '05 c-1 pic aaa.' '05 c-3 pic 99.'
StringList3 will contain 'c-2' '07 d-1 pic zzz.' '07 d-2 pic xxx.'
StringList4 will contain 'b-5' '05 e-1 pic zzz.'

At the end of the program I will(for example) write the StringList's 
to disk. But I can't write anyone before the program end.


I had thinked hard about it. I can't create StringList with a variable 
name. I must previously  declare each one in my pascal source. How can 
I solve the trouble proposed?

I can't create StringList with a variable name.

I don't know how much pascal experience you have. and I am not 100% sure 
what this line means, but taking a guess:
You need a way to store stringlist2 in stringlist1 = So that if you 
later read the list, you can read the nested lists too?


You do not need a variable for each Stringlist you create.

Procedure AddNestedStringlist(OuterStringlist: TStringList; Text: String);
var
 InnerStringList: TStringlist;
begin
 InnerStringList := TStringlist.Create;
 OuterStringlist.AddObject(Text, InnerStringlist);
end;

Thats it. Note that there is no InnerStringlist.Free.


The stringlist you created is not bound to the variable 
InnerStringlist. It is just a stringlist in memory, and any variable 
(of the correct type) can refer to it.


To read the variable back (you need a type cast):
NextedStringList := TStringList(OuterStringList.Objects[n]);


Before you Free OuterStringlist, you have to check for any 
InnerStringlist and destroy it, or you will leak memory.




Note that when I'm appending strings in a StringList, it's possible 
that I must create a new StringList(or various), put data in it(or 
them) and return to put data in the first StringList.


If the solution is obvious I beg your pardon. I can't find it. * *


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

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


off-topic [Re: [fpc-pascal] proxy for sql]

2009-03-19 Thread Martin Friebe

Andreas Berger wrote:
This isn't really a FPC question, but since the application is being 
written in FPC I thought I would ask here.


I am developing an application that controls machinery. The 
application will store everything that happens in a SQL database. Some 
clients (restricted) should have permission to access the database to 
generate their own reports via some 3rd party report generation 
software of their choice. However I want to restrict who has access 
without placing a user password on the SQL server since some clients 
purchase multiple instances of the SW but not all options.


1) Is it possible to place my app between the 3rd party app and the 
SQL server? How would I do this.
2) Is it possible to configure the SQL server to query my app to see 
if a user can log on?

3) Any other ideas?

Regards,
Andreas
Well I imagine that will be hard to do, if you do it in FPC (since you 
may have to start from scratch).
I don't think there is a component emulating the mysql server interface. 
Rewriting the server (just the protocol part) is a lot of work.


You may want to look at the mysql site, they have a mysql-proxy, which 
can be controlled by LUA script. So that my do the trick for you. You 
could probably replace the client credentials inside the proxy. Make 
sure you forward using a restricted account. Otherwise you must ensure 
that nothing in the sql could ever violate the permissions.


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


Re: [fpc-pascal] proxy for sql

2009-03-19 Thread Martin Friebe

Andreas Berger wrote:
This isn't really a FPC question, but since the application is being 
written in FPC I thought I would ask here.


I am developing an application that controls machinery. The 
application will store everything that happens in a SQL database. Some 
clients (restricted) should have permission to access the database to 
generate their own reports via some 3rd party report generation 
software of their choice. However I want to restrict who has access 
without placing a user password on the SQL server since some clients 
purchase multiple instances of the SW but not all options.


1) Is it possible to place my app between the 3rd party app and the 
SQL server? How would I do this.
2) Is it possible to configure the SQL server to query my app to see 
if a user can log on?

3) Any other ideas?

Here is another idea.

You would still need a user on the DB, to limit what can be accessed. 
But to check if access should be granted (allow or deny tcp) you can use 
your own software.
All you need is some sort of Proxy/socket forwarder, that you can 
implement using FPC.


The Tool would run on the users local PC or Server. It would accept 
connections for the database, and forward the Connection straight to the 
real DB (or maybe encrypt it, using whatever access control). Of course 
if the user is not allowed to connect at all, you do not make the forward.


The user could have a key(public/private), so if you remove the opposite 
on the server, the user can no longer connect.


However this acts like a tunnel, so you do not get any control on the 
SQL itself.  The SQL server needs to be configured to restrict access to 
the permitted data.


Best Regards
Martin

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


[fpc-pascal] csLoading and Create

2009-01-14 Thread Martin Friebe

Hi,

If a component is loaded from a stream, then csLoading is set in 
ComponentState (or so I thought I understood the concept)

So in my component i do  if not(csLoading in componentState) ...

However I found this does not work in the constructor Create. csLoading  
is only set *after* the Constructor has been called.

(This is unless it is an inline component?).
- TReader does create the object with class.NewInstance (so create is 
not yet called)
- the for inlined components it does set csInline, scLoading = for 
others it does not set anything

- then the constructor create is called (but csLoading is not set)
- only then does csLoading get set

Is this supposed to be like this? How else can I inside Create check if 
the component is loaded from a stream?


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


Re: [fpc-pascal] csLoading and Create

2009-01-14 Thread Martin Friebe

Michael Van Canneyt wrote:

On Wed, 14 Jan 2009, Martin Friebe wrote:
  

Hi,

If a component is loaded from a stream, then csLoading is set in
ComponentState (or so I thought I understood the concept)
So in my component i do  if not(csLoading in componentState) ...

However I found this does not work in the constructor Create. csLoading  is
only set *after* the Constructor has been called.
(This is unless it is an inline component?).
- TReader does create the object with class.NewInstance (so create is not yet
called)
- the for inlined components it does set csInline, scLoading = for others it
does not set anything
- then the constructor create is called (but csLoading is not set)
- only then does csLoading get set

Is this supposed to be like this? How else can I inside Create check if the
component is loaded from a stream?



It is supposed to be like this. You cannot check this, and you shoud not.
A component should always behave the same, no matter whether it is being
streamed or not: You cannot a priori know whether a component of a certain
class will be streamed or not.
  

So here is my problem.

I have a component, that may or may not have children. If it has 
children they are correctly streamed, and read back too.


Historically it did not have children (or more accurate, it did, but 
they did not get streamed, they where constant)


Now I want to make sure that:
- a newly created (not loaded) component behaves as before. It creates 
it's default children.
- a loaded component however can not do with this default created 
children = because they would be duplicates.


Simply replacing isn't going to work, since their amount can vary. (0, 1 
or more).
In fact in Lazarus I probably going to check the LCLVersion property of 
the form (or something like that). = This is for loaded components = 
new componets always will have the default.


In any way, currently this default children are created in the 
constructor, so it would have been nice to know if it was loaded or not.


Question:
- Is there a better place to create those defaults? One where I can 
access the necessary information?
- Alternative ReadState comes to mind. I can intercept it, and clear 
out the defaults, since loading is about to happen. (then call inherited)


Any better Idea?

Another question:
The component described are Subcomponents, and they are not visible. I 
will probably have them parented and owned by the same visible control.
(  The only reason to stream them as component is because they vary in 
number and can be of different classes. I can not do that through a 
property, nor through a collection:

  Property is fixed in number and class
  Collection(Item) is fixed in class, only variable in number
)

It seems to work with the default setting.
But I was wondering if in such a scenario I should have to thing about 
csInline, csAncestor or csInherited? Probably not?


Thanks and Best Regards
Martin

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


Re: [fpc-pascal] SQL show tables

2009-01-13 Thread Martin Friebe

Joost van der Sluis wrote:

Op maandag 12-01-2009 om 13:30 uur [tijdzone -0500], schreef David B
Copeland:

  

Query: Cannot open a non-select statement



'show tables' is not a valid sql-statement. It is a MySQL-hack. The
TODBCConnection can not see that it is connected to a MySQL server and
thus doesn't recognise this statement as a select-statement. If you use
a TMySQLConnection it will work. You can fill in a bug report to ask if
TODBCConnection can recognise 'show' as 'select'. We'll have to look
what kind of effect that has on other (really sql-based)
database-servers.
  
If you (the original poster) uses Mysql 5 or up, then Show tables is 
not needed. Use the information-schema instead


SELECT table_name FROM INFORMATION_SCHEMA.TABLES  WHERE table_schema = 
'/|db_name|/'


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


Re: [fpc-pascal] Saving user created component structure to LFM file

2009-01-12 Thread Martin Friebe

Hi,

I may have found a way top solve my problem (saving a list of components 
from various places, not necesarely all nested in the top level 
component / See below)


The question now is, how forward-compatible is this ode. How much do I 
have to expect any of the current code to change in ways that would 
break my solution?


What I would do:
The outer container has no nested components of it's own. It seems I can 
hook into (override) TComponent.WriteState which is calling 
WriteComponentData (properties, then Children). Since no children are 
there, I can make my own calls to WriteComponent from there, supplying 
all the components, of all the helper objects.


On Read, I can Hook into ReadState. I can let the reader add them 
normally, and sort them out/once they have been read by the reader. I 
ReadState, I can also sort out to get rid of the default list of 
objects/components (since new ones are loaded).  This must be in 
ReadState, not in Loaded, because Loaded is called after, and I would 
run into trouble making the diff between the default, and reloaded objects)


The generated LFM file definitely looks like any LFM file (it has a 
component, with properties first then other nested Components)


Any ideas, if this is a bad idea (like in will break soon)?

Thanks Martin


Martin Friebe wrote:

Hi, I have a problem saving a certain component struicture to an LFM
(lazarus) file and read it back.

since a good amount of code is in FPC, I am not sure which list to go to?

There is classes/writer.inc with has TBinaryObjectWriter. This is where
things go first.
Then, later this gets translated into text. This translation seems to be
stricter in terms of  what can be nested.


Anyway the problem is, that if I want to save a component (that can be
of different class/classes) then I can use WriteComponent. But only if I
am in a Component that is itself written with WriteComponent.

In the final LFM it seems a Component can only be nested in an other
component. It does not seem to be possible to put it in:
- Not in a subcomponent (because a subcomponent does not write it's
class, but just the properties that are visible for the class given by
the property
property Foo: TPanel read .. write ...
 writes
Foo.Name = 'abc'
Foo.Top = 1
...
- Not in a TCollection, or at least I havent managed. Also again a
TCollection is restricted to one classs for all Items
- Not Using DefineProperties
 All propwerties with define property are of the kind
 Name = Value
 I can add a list, but even inside the list I can not write a component


What I want to archive is theFollowing. I have

TMainComponent = class (foo)
  property Options : TPersitentBar read  x write x;
end

If It has to be it can be a TComponent, with SubComponent in
TComponentStyle.
Problem 1)   Options is always created in the constructor, it can not be
stored as a nested Component in the LFM. If it was, it would exist twice
(once created in the constructor, and once loaded from the lfm)

TPersitentBar should have a list of components, variable number, and
different subclasses (could inherit from TPersistent, only Component if
it makes it easier)

How can I get this list saved into the lfm? Each item has a diff class,
and diff properties, so they must saved via WriteComponent. (Which does
not work for DefineProerties)

And of course a default list of items is created in the constructor, so
I need to detect if they are loaded, and remove the defaults.

Any Idea?

Example of the final structure (if only it was valid)

object MainComp1 : TMainComponent
 Options.AllowFoo = 1
 Options.AllowABC = 2
 object Options.SubOptionsForCars : TCarOptions
 MAxCar = 4
 end
 object Options.SubOptionsForTrains : TTrainOptions
 MAxTrain = 1
 end
end


Best Regards
Martin





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


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


[fpc-pascal] Saving user created component structure to LFM file

2009-01-11 Thread Martin Friebe

Hi, I have a problem saving a certain component struicture to an LFM
(lazarus) file and read it back.

since a good amount of code is in FPC, I am not sure which list to go to?

There is classes/writer.inc with has TBinaryObjectWriter. This is where
things go first.
Then, later this gets translated into text. This translation seems to be
stricter in terms of  what can be nested.


Anyway the problem is, that if I want to save a component (that can be
of different class/classes) then I can use WriteComponent. But only if I
am in a Component that is itself written with WriteComponent.

In the final LFM it seems a Component can only be nested in an other
component. It does not seem to be possible to put it in:
- Not in a subcomponent (because a subcomponent does not write it's
class, but just the properties that are visible for the class given by
the property
property Foo: TPanel read .. write ...
 writes
Foo.Name = 'abc'
Foo.Top = 1
...
- Not in a TCollection, or at least I havent managed. Also again a
TCollection is restricted to one classs for all Items
- Not Using DefineProperties
 All propwerties with define property are of the kind
 Name = Value
 I can add a list, but even inside the list I can not write a component


What I want to archive is theFollowing. I have

TMainComponent = class (foo)
  property Options : TPersitentBar read  x write x;
end

If It has to be it can be a TComponent, with SubComponent in
TComponentStyle.
Problem 1)   Options is always created in the constructor, it can not be
stored as a nested Component in the LFM. If it was, it would exist twice
(once created in the constructor, and once loaded from the lfm)

TPersitentBar should have a list of components, variable number, and
different subclasses (could inherit from TPersistent, only Component if
it makes it easier)

How can I get this list saved into the lfm? Each item has a diff class,
and diff properties, so they must saved via WriteComponent. (Which does
not work for DefineProerties)

And of course a default list of items is created in the constructor, so
I need to detect if they are loaded, and remove the defaults.

Any Idea?

Example of the final structure (if only it was valid)

object MainComp1 : TMainComponent
 Options.AllowFoo = 1
 Options.AllowABC = 2
 object Options.SubOptionsForCars : TCarOptions
 MAxCar = 4
 end
 object Options.SubOptionsForTrains : TTrainOptions
 MAxTrain = 1
 end
end


Best Regards
Martin





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


Re: [fpc-pascal] for .. in loop implementation [off topic - goto ?]

2009-01-10 Thread Martin Friebe

Vinzent Höfler wrote:

Jürgen Hestermann wrote:


Mantra: First make it work, then make it fast.
In general that's true from the programmer's viewpoint. But this does 
not apply to adding language details because there is no 'first make 
it work'. Why obscure important implementation details if the only 
benefit is saving some writing?


I won't judge on the only save some writing here, but generally it 
*does* apply to language features: If a particular language feature 
helps you writing correct code faster (by supporting you to make it 
work instead of relying on your abilities to use the debugger), then 
it does apply.


The real question is if the (or any other) proposal is good enough 
to do just that, or if it's really some syntactic sweetener (not even 
sugar, sugar at least contains energy). That's something to discuss.


Let me take a rather extreme point of view: After all, all those for-, 
while-, and repeat-until-loops are only there to save you from some 
typing work[0], because Pascal already has a perfectly good 
loop-construct with which you can do all that: goto. Would you agree 
here? Probably not.
1) goto alone (labels assumed) can not replace any of the loop 
constructs. It must be paired with if (or anything to check conditions)


2) Otherwise you are of course right. Following this logic however most 
programming languages (including pascal and assembler) become redundant. 
They have far to many instructions to archive the same thing.
Look at languages like whitespace or brainfuck and you will see that 
a language which is kept simple (by the meaning of no unneeded 
instructions does not need more than 6 to 8 instructions.


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


[fpc-pascal] a few installation issues (trunc on freebsd)

2008-11-03 Thread Martin Friebe

I have a few question, regarding my attempts to install fpc from trunc
(I read the build faq, yet I have not succeeded...)

On a freebsd (7.0) box, I have downloaded and installed the pre-compiled
fpc 2.2.2 ( to use as my initial compiler.)

I have created my workind dir /data/fpc_trunc/svn and done my checkout
(Revision: 12021)
 cd /data/fpc_trunc/snv
 svn co http://svn.freepascal.org/svn/fpc/trunk .

then according to the build-faq, I have done
 cd compiler
 gmake cycle

* First problem: I found if I simply go to the parent (svn) directory,
and do a gmake all PP=/data/fpc_trunc/svn/compiler/ppc386 there, it
will do some clean out, and stop because halfway through it will have
deleted this compiler.

So instead (which is not mentioned in the buildfaq?), I have installed
the compiler and rtl at this stage:
  gmake install  INSTALL_PREFIX=/data/fpc_trunc/inst/
  cd ../rtl
  gmake install  INSTALL_PREFIX=/data/fpc_trunc/inst/

Note: I am installing to a separate dir, as I want to use this
installation in parallel to other installations.

* Second Problem: when using fpc (instead of ppc), it will always find
the ppc386 in the default installation. The only way I can change this
is fpc -Xp/path/to/my/ppc386. (Which I found no documentation for. I
got that from looking through the source) However, if I want to use fpc
from lazarus, I may not be able to pass that (convenient) on the command
line.
Is there any INI file? (fpc.cfg did not help here, at least not the
fpc.cfg in the same path as fpc exe).
Or is it save to substitute fpc, with ppc386 everywhere it is called?

any way I then go and create my fpc.cfg:
 cd ../../inst
 ./bin/fpcmkcfg -d basepath=/data/fpc_trunc/inst/lib/fpc/2.2.2 
bin/fpc.cfg

* 3rd problem, it uses the same prefix for the units (-Fu) and the bin
(-FD), so the above creates correct -Fu config, but I must change the
-FD conf. Any solution to this ?
-Fu will be correct:
 -Fu/data/fpc_trunc/inst/lib/fpc/2.2.2/units/$FPCTARGET/rtl
but -FD will *NOT* be (which I think it should?, or am I wrong?)
 -FD/data/fpc_trunc/inst/bin

now I go back to the top svn checkout and to
  gmake all PP=/data/fpc_trunc/inst/lib/fpc/2.2.2/ppc386


* 4th Problem the compilation aborted (Sorry I don't remember where)
because it tried to access the x11 package
= I did solve that by going int packages/x11, did the make there, and
did install it (with the install prefix)

* 5th problem packages/graph stops, because it tries to use x86. (This
exists in the sources rtl/unix/x86.pp) Somehow all the above has not
installed this (not on my FreeBSD), the package is missing int he
inst/lib directory


And last not least, having checked out trunc (or being under the
impression to have done so), why has the make install in the rtl
installed something with 2.2.2 in the path? (If I run the ppc386 that
was installed it will say 2.3.1.
Maybe this last bit will solve some of the other questions...


Any help is greatly appreciated. Many thanks.
Martin



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


Re: [fpc-pascal] a few installation issues (trunc on freebsd)

2008-11-03 Thread Martin Friebe

Thanks for the help below.

Here is the x86 related error. I did (working directory:
/data/fpc_trunc/svn )
 svn up
 svn info
Path: .
URL: http://svn.freepascal.org/svn/fpc/trunk
Repository Root: http://svn.freepascal.org/svn/fpc
Repository UUID: 3ad0048d-3df7-0310-abae-a5850022a9f2
Revision: 12025
Node Kind: directory
Schedule: normal
Last Changed Author: jonas
Last Changed Rev: 12025
Last Changed Date: 2008-11-03 21:18:27 + (Mon, 03 Nov 2008)

 gmake distclean
 gmake all

The last lines from this make are below. At this stage it is using
ppc386 from the cvn directory, and it is also using the rtl from svn.
 /data/fpc_trunc/svn/compiler/ppc386 -V
Free Pascal Compiler version 2.3.1 [2008/11/03] for i386
Copyright (c) 1993-2008 by Florian Klaempfl

The Error, I get

gmake[3]: Leaving directory `/data/fpc_trunc/svn/packages/openssl'
gmake -C graph smart
gmake[3]: Entering directory `/data/fpc_trunc/svn/packages/graph'
gmake all LINKSMART=1 CREATESMART=1
gmake[4]: Entering directory `/data/fpc_trunc/svn/packages/graph'
/bin/mkdir -p units/i386-freebsd
/data/fpc_trunc/svn/compiler/ppc386 -XX -CX -Ur -Xs -O2 -n -S2
-Fu/data/fpc_trunc/svn/rtl/units/i386-freebsd
-Fu/data/fpc_trunc/svn/packages/pthreads/units/i386-freebsd
-Fu/data/fpc_trunc/svn/packages/x11/units/i386-freebsd
-Fu/data/fpc_trunc/svn/packages/sdl/units/i386-freebsd -Fisrc/freebsd
-Fisrc/inc -Fisrc/unix -FE. -FUunits/i386-freebsd -di386 -dRELEASE
-Isrc/inc src/unix/graph.pp
Fatal: Can't find unit x86 used by Graph
Fatal: Compilation aborted
gmake[4]: *** [graph.ppu] Error 1
gmake[4]: Leaving directory `/data/fpc_trunc/svn/packages/graph'
gmake[3]: *** [fpc_smart] Error 2
gmake[3]: Leaving directory `/data/fpc_trunc/svn/packages/graph'
gmake[2]: *** [graph_smart] Error 2
gmake[2]: Leaving directory `/data/fpc_trunc/svn/packages'
gmake[1]: *** [packages_smart] Error 2
gmake[1]: Leaving directory `/data/fpc_trunc/svn'
gmake: *** [build-stamp.i386-freebsd] Error 2

Any idea?




But thanks for the hint on make install
 gmake install FPC=xxx  INSTALL_PREFIX=foo
worked well (created a 2.3.1 dir)
Same if I use PP= instead of FPC=. Is there a difference?

I looked at the buildfaq at http://www.stack.nl/~marcov/buildfaq.pdf
(not sure if this is up to date?)
Chapter 2, pages 22: The first 2 examples have make install with *no*
PP=. Of course my fault, I didn't read properly. It then explains that
they are wrong.

Maybe it would be easier for users to follow if either no wrong examples
where given, or maybe the hint # wrong example was given on the same
line as the command. So you would more liekly get to read it, if you
copied and pasted it?
I know it's my fault not to read it proper. But i could imagine, that
othere may get into similar trouble...

Thanks Martin


Jonas Maebe wrote:


On 03 Nov 2008, at 16:03, Martin Friebe wrote:


I have a few question, regarding my attempts to install fpc from trunc


Small aside: it's trunk (as in trunk of a tree, compared to 
branches), not trunc (as in truncate).



* First problem: I found if I simply go to the parent (svn) directory,
and do a gmake all PP=/data/fpc_trunc/svn/compiler/ppc386 there, it
will do some clean out, and stop because halfway through it will have
deleted this compiler.


That's correct.


So instead (which is not mentioned in the buildfaq?), I have installed
the compiler and rtl at this stage:
 gmake install  INSTALL_PREFIX=/data/fpc_trunc/inst/
 cd ../rtl
 gmake install  INSTALL_PREFIX=/data/fpc_trunc/inst/


You don't have to install the compiler/rtl. You only have to copy the 
compiler binary someplace safe. In face, you don't need the cycle at 
all, you can immediately do a gmake all.



* Second Problem: when using fpc (instead of ppc), it will always find
the ppc386 in the default installation. The only way I can change this
is fpc -Xp/path/to/my/ppc386. (Which I found no documentation for. I
got that from looking through the source) However, if I want to use fpc
from lazarus, I may not be able to pass that (convenient) on the command
line.


Does lazarus call fpc or ppcXXX?


Is there any INI file?


No.


(fpc.cfg did not help here, at least not the
fpc.cfg in the same path as fpc exe).
Or is it save to substitute fpc, with ppc386 everywhere it is called?


Yes, that's safe.


any way I then go and create my fpc.cfg:
cd ../../inst
./bin/fpcmkcfg -d basepath=/data/fpc_trunc/inst/lib/fpc/2.2.2 
bin/fpc.cfg


I'm not sure how well maintained fpcmkcfg is. For the (*nix) releases 
we use the samplecfg script (from compiler/utils) to generate 
configurations. But you shouldn't need a new configuration file, afaik 
samplecfg is identical in fixes and trunk (and in 2.2.2).



* 3rd problem, it uses the same prefix for the units (-Fu) and the bin
(-FD), so the above creates correct -Fu config, but I must change the
-FD conf. Any solution to this ?
-Fu will be correct:
-Fu/data/fpc_trunc/inst/lib/fpc/2.2.2/units/$FPCTARGET/rtl
but -FD will *NOT* be (which I think it should?, or am I wrong