[fpc-pascal] How to get address of MyFunction in MyFunction?

2010-07-18 Thread Žilvinas Ledas
Hello all, to get address of function I can use @MyFunction, but if I use it within MyFunction - I get address of Result. How can I get address of current function? (It's not for assigning to something else. It is for a kind of self modifying code.) Regards Žilvinas Ledas ___

Re: [fpc-pascal] How to get address of MyFunction in MyFunction?

2010-07-18 Thread Jonas Maebe
On 18 Jul 2010, at 12:11, Žilvinas Ledas wrote: > to get address of function I can use @MyFunction, but if I use it within > MyFunction - I get address of Result. How can I get address of current > function? @unitname.function (or @programname.function if you are in the main program file) J

Re: [fpc-pascal] How to get address of MyFunction in MyFunction?

2010-07-18 Thread Jonas Maebe
On 18 Jul 2010, at 12:50, Jonas Maebe wrote: > On 18 Jul 2010, at 12:11, Žilvinas Ledas wrote: > >> to get address of function I can use @MyFunction, but if I use it within >> MyFunction - I get address of Result. How can I get address of current >> function? > > @unitname.function (or @progr

Re: [fpc-pascal] How to get address of MyFunction in MyFunction?

2010-07-18 Thread Žilvinas Ledas
On 2010-07-18 13:51, Jonas Maebe wrote: On 18 Jul 2010, at 12:50, Jonas Maebe wrote: On 18 Jul 2010, at 12:11, Žilvinas Ledas wrote: to get address of function I can use @MyFunction, but if I use it within MyFunction - I get address of Result. How can I get address of current func

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Sven Barth
Hi! You can use WriteStr to "Writeln" to a String (needs 2.4.0 and above). Example: var s: String; begin WriteStr(s, 'Hello World'); end; Also you can try unit StreamIO (in fcl-base) which allows you to use Streams as TextFiles (you can also look at it to learn how to implement your own

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Sven Barth
Hi again! I forgot to mention: If you want to redirect StdOut (or Output as the variable is called in Pascal) you need to assign a new TextFile to Output (but keep the old one around and assign it back later when your application is terminating). Example: var oldoutput, f: TextFile; begin

Re: [fpc-pascal] How to get address of MyFunction in MyFunction?

2010-07-18 Thread Jonas Maebe
On 18 Jul 2010, at 13:14, Žilvinas Ledas wrote: > I want to use it this way: > 1) Gel all @unitname.function addresses. > 2) Use disassembler to find nearest next RET. > 3) Then I assume that I have start and end of the function in the binary file. > > It works at least for the concept-showing a

Re: [fpc-pascal] How to get address of MyFunction in MyFunction?

2010-07-18 Thread Žilvinas Ledas
On 2010-07-18 15:42, Jonas Maebe wrote: On 18 Jul 2010, at 13:14, Žilvinas Ledas wrote: I want to use it this way: 1) Gel all @unitname.function addresses. 2) Use disassembler to find nearest next RET. 3) Then I assume that I have start and end of the function in the binary file. It work

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Bernd
2010/7/18 Sven Barth : > Also you can try unit StreamIO (in fcl-base) which allows you to use Streams > as TextFiles (you can also look at it to learn how to implement your own > text driver). This looks more promising, streams seem to be a more high level implementation of such concepts. I'm cur

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Sven Barth
Hi! On 18.07.2010 17:07, Bernd wrote: But I do not understand the following: function TStream.Write(const Buffer; Count: Longint): Longint; what type is Buffer? How does it get away with the missing type declaration without the compiler failing to compile this at all? Quote from the Docs (

[fpc-pascal] Extending an enumeration

2010-07-18 Thread Mark Morgan Lloyd
If I have a class with a property Phase: TrrPhase where TrrPhase is an enumeration such as (rrQuiescent, rrInitialised), is there an elegant way of extending the enumeration and overriding the property type so that a derived class can use the new values? -- Mark Morgan Lloyd markMLl .AT. tel

Re: [fpc-pascal] Extending an enumeration

2010-07-18 Thread Jetcheng Chu
As far as I know, properties cannot be overridden. However, you could consider using subrange types, as the example below shows. type Fruit = (Apple, Banana, Cherry, Orange, Pineapple); LimitedFruit = Apple..Cherry; You can use the full enumeration as the property's type, and then restrict i

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Bernd
OK, I got it working now. Just in case somebody else is googling for something like this: first I define a class TDebugStream that will later replace the standard output: Type TDebugStream = class(TStream) function Write(const Buffer; Count : Longint) : Longint; override; end; implementa

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Michael Van Canneyt
On Sun, 18 Jul 2010, Bernd wrote: OK, I got it working now. Just in case somebody else is googling for something like this: first I define a class TDebugStream that will later replace the standard output: Type TDebugStream = class(TStream) function Write(const Buffer; Count : Longint) :

Re: [fpc-pascal] redirecting stdout

2010-07-18 Thread Bernd
2010/7/18 Michael Van Canneyt : > I think that simply > > AssignStream(Output,S); > Rewrite(Output); > > Probably would work as well. Yes, you are of course right, this is simpler. I just forgot to simplify it after I was initially playing around and experimenting with a separate file and without

Re: [fpc-pascal] Extending an enumeration

2010-07-18 Thread Mark Morgan Lloyd
Jetcheng Chu wrote: As far as I know, properties cannot be overridden. However, you could consider using subrange types, as the example below shows. type Fruit = (Apple, Banana, Cherry, Orange, Pineapple); LimitedFruit = Apple..Cherry; You can use the full enumeration as the property's typ

[fpc-pascal] Initialize the object (not class)

2010-07-18 Thread Zaher Dirkey
I have used object to make more easy, not need to create or free it, MyObject = object private FProp1: integer; public Prop1: integer read FProp1 write FProp1 procedure Proc1; end; used like var O: MyObject; begin O.Proc1; end; 1 - The problem, i have random value in the prop1(I am not

Re: [fpc-pascal] Initialize the object (not class)

2010-07-18 Thread Jonas Maebe
On 18 Jul 2010, at 21:01, Zaher Dirkey wrote: > MyObject = object > private > FProp1: integer; > public > Prop1: integer read FProp1 write FProp1 > procedure Proc1; > end; > > used like > var > O: MyObject; > begin > O.Proc1; > end; > > 1 - The problem, i have random value in the prop1(I a

Re: [fpc-pascal] Initialize the object (not class)

2010-07-18 Thread Zaher Dirkey
On Sun, Jul 18, 2010 at 10:20 PM, Jonas Maebe wrote: > > 2 - is there a method i can override it to init my properties without to > > call it manualy O.init; > > No. Can i ask to be an "Feature Request" in FPC? Thanks -- Zaher Dirkey ___ fpc-pascal

Re: [fpc-pascal] Extending an enumeration

2010-07-18 Thread Jetcheng Chu
> Yes, I was thinking that. However if the basic class was say a > round-robin scheduler with phases rrQuiescent and rrInitialised and the > descendant was say an HP comms protocol handler with additional phases > hpReceivingPadding, hpReceivedSync and so on it would seem to be > questionable pract