Re: [fpc-pascal] Mode Delphi and functions as parameters.

2015-03-21 Thread Constantine Yannakopoulos
On Fri, Mar 20, 2015 at 11:55 AM, Michael Schnell 
wrote:

> what to to if a function has no parameter and returns a value that is a
> pointer to a function of exactly this type ?


​The logical thing for the compiler would be to assume that the programmer
meant that a reference should be passed​. If the programmer wanted to
invoke the function ans pass the result reference they should use empty
parentheses aka "the invocation operator":

CallFunction(SomeFunction); // passes a reference to SomeFunction.
CallFunction(SomeFunction()); // passes the result of the invocation of
SomeFunction.

​So no ambiguity, albeit a very subtle semantic difference that can easily
produce bugs.​ But IMHO the "@" notation isn't much better either.

PS: I tend to always use the "()" notation when invoking functions with no
arguments so it will be clear to a future reader that I'm invoking a
function and not assigning some variable. Makes a difference with poorly
named functions (not starting with a verb):

ADate := Date;
ADate := Date();
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Where is the 'write' function defined and how is it different from 'writeln'?

2015-03-21 Thread vfclists .
On 20 March 2015 at 20:54, Sven Barth  wrote:

> On 20.03.2015 21:18, vfclists . wrote:
>
>>
>>
>> On 20 March 2015 at 19:34, Sven Barth > > wrote:
>>
>> Am 20.03.2015 19:19 schrieb "vfclists ." > >:
>>
>
snip

> How do you ensure own implementation overrides the system's
>> implementation, does the compiler take care of that automatically, or
>> will you have to name your function differently?
>>
>
> There is no need to ensure that. Here is an example:
>
> === code begin ===
>
> var
>   f, oldout: TextFile;
> begin
>   Writeln('Hello Output as StdOut');
>
>   oldout := Output;
>
>   Assign(Output, 'test.txt');
>   Rewrite(Output);
>
>   Writeln('Hello Output as file');
>
>   Close(f);
>
>   Output := oldout;
>
>   Writeln('Hello Output as StdOut again');
> end.
>
> === code end ===
>
> To see how such a TextFile is implemented you can take a look at unit
> StreamIO which is part of FPC's units.
>
> (Though I wonder why "Assign(f, 'test.txt'); Output := f; Writeln('Hello
> Output as file');" does not work :/ )
>
> Regards,
> Sven
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>

I need to get the output of a program which uses a lot of Write and Writeln
commands into the GUI in realtime, by that I not having to output it to a
text file and reading it afterwards, but by capturing the output of each
Write command into a variable and displaying it in the GUI immediately.

If each Write or Writeln could trigger an event, I could use the event to
capture the output. My other option is to replace the calls to write with
my own function, but Write has different number of call parameters and it
may require as many variants of the function as are used in the program,
assuming that the call syntax is regular, not something like this one -
write(JSValToDouble(cx,pom^)):1:scale).

-- 
Frank Church

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

Re: [fpc-pascal] Where is the 'write' function defined and how is it different from 'writeln'?

2015-03-21 Thread Florian Klaempfl
Am 21.03.2015 um 11:13 schrieb vfclists .:
> I need to get the output of a program which uses a lot of Write and
> Writeln commands into the GUI in realtime, by that I not having to
> output it to a text file and reading it afterwards, but by capturing the
> output of each Write command into a variable and displaying it in the
> GUI immediately.
> 
> If each Write or Writeln could trigger an event, I could use the event
> to capture the output. My other option is to replace the calls to write
> with my own function, but Write has different number of call parameters
> and it may require as many variants of the function as are used in the
> program, assuming that the call syntax is regular, not something like
> this one - write(JSValToDouble(cx,pom^)):1:scale).

Check the implementation of the FPC CRT unit how a unit can hook into
the write(ln) mechanisms:

http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/rtl-console/src/unix/crt.pp?revision=26372&view=markup

Have a look at AssignCrt and CrtOpen, how it is done.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Mode Delphi and functions as parameters.

2015-03-21 Thread Jürgen Hestermann


Am 2015-03-21 um 11:04 schrieb Constantine Yannakopoulos:

PS: I tend to always use the "()" notation when invoking functions with no 
arguments so it will be clear to a future reader that I'm invoking a function and not 
assigning some variable.


This should be the job of the langugage definition, not of the programmer:
Avoid ambiguity, do not base anything on assumptions.
That avoids bugs by making it very clear to the programmer what realy happens.

Saving one or 2 key keystrokes is of no use.
A clear language definition is what makes the essence of a programming language.

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


Re: [fpc-pascal] Where is the 'write' function defined and how is it different from 'writeln'?

2015-03-21 Thread Sven Barth

On 21.03.2015 11:13, vfclists . wrote:



On 20 March 2015 at 20:54, Sven Barth mailto:pascaldra...@googlemail.com>> wrote:

On 20.03.2015 21:18, vfclists . wrote:



On 20 March 2015 at 19:34, Sven Barth
mailto:pascaldra...@googlemail.com>
>> wrote:

 Am 20.03.2015 19:19 schrieb "vfclists ."
mailto:vfcli...@gmail.com>
 >>:


snip

How do you ensure own implementation overrides the system's
implementation, does the compiler take care of that
automatically, or
will you have to name your function differently?


There is no need to ensure that. Here is an example:

=== code begin ===

var
   f, oldout: TextFile;
begin
   Writeln('Hello Output as StdOut');

   oldout := Output;

   Assign(Output, 'test.txt');
   Rewrite(Output);

   Writeln('Hello Output as file');

   Close(f);

   Output := oldout;

   Writeln('Hello Output as StdOut again');
end.

=== code end ===

To see how such a TextFile is implemented you can take a look at
unit StreamIO which is part of FPC's units.

(Though I wonder why "Assign(f, 'test.txt'); Output := f;
Writeln('Hello Output as file');" does not work :/ )

Regards,
Sven

_
fpc-pascal maillist  - fpc-pascal@lists.freepascal.__org

http://lists.freepascal.org/__cgi-bin/mailman/listinfo/fpc-__pascal



I need to get the output of a program which uses a lot of Write and
Writeln commands into the GUI in realtime, by that I not having to
output it to a text file and reading it afterwards, but by capturing the
output of each Write command into a variable and displaying it in the
GUI immediately.

If each Write or Writeln could trigger an event, I could use the event
to capture the output. My other option is to replace the calls to write
with my own function, but Write has different number of call parameters
and it may require as many variants of the function as are used in the
program, assuming that the call syntax is regular, not something like
this one - write(JSValToDouble(cx,pom^)):1:scale).


The usage of a text file was merely an example. As I said there already 
is the possibility to use a TStream provided by FPC. But since I'm nice 
here you also have an example for a TMemo, I'm sure you can adjust that 
for your needs:


=== code begin ===

resourcestring
  SErrNilMemo = 'Memo is nil';

type
  PMemo = ^TMemo;

function GetMemo(var F: TTextRec): TMemo;
begin
  Result:=PMemo(@F.Userdata)^;
end;

function MemoWrite(var F: TTextRec): LongInt;
var
  s: String;
begin
  Result := 0;
  with F do
if BufPos > 0 then
  try
SetLength(s, BufPos);
Move(BufPtr^, s[1], BufPos);
GetMemo(F).SelText := s;
BufPos:=0;
  except
Result:=101;
  end;
end;


function MemoClose(var F: TTextRec): LongInt;
begin
  Result := 0;
end;

function MemoOpen(var F: TTextRec): LongInt;
begin
  Result := 0;
  with F do begin
BufPos:=0;
Bufend:=0;
case Mode of
  fmInput: begin
Result := 104;
  end;
  fmOutput, fmAppend: begin
InOutFunc := @MemoWrite;
FlushFunc := @MemoWrite;
if Mode = fmAppend then
  Try
with GetMemo(F) do begin
  SelStart := Length(Text);
end;
  except
Result := 156;
  end;
end else begin
  GetMemo(F).Clear;
end;
end;
end;
end;

procedure AssignMemo(var F: Text; aMemo: TMemo);
var
  e: EInoutError;
begin
  if not Assigned(aMemo) then begin
E:=EInOutError.Create(SErrNilMemo);
E.ErrorCode:=6;
Raise E;
  end;
  with TTextRec(F) do begin
OpenFunc := @MemoOpen;
CloseFunc := @MemoClose;
case DefaultTextLineBreakStyle Of
  tlbsLF:
TextRec(f).LineEnd := #10;
  tlbsCRLF:
TextRec(f).LineEnd := #13#10;
  tlbsCR:
TextRec(f).LineEnd := #13;
end;
PMemo(@UserData)^ := aMemo;
Mode := fmClosed;
BufSize := SizeOf(Buffer);
BufPtr := @Buffer;
Name[0] := #0;
  end;
end;

=== code end ===

To use it you should use the following code (for example in FormCreate):

=== code begin ===

  fOldOutput := Output; // store the old Output somewhere
  AssignMemo(Output, Memo1);
  Rewrite(Output);

=== code end ===

Then in FormDestroy you cleanup:

=== code begin ===

  CloseFile(Output);
  Output := fOldOutput; // restore old Output

=== code end ===

And to illustrate that it works I've used a TTimer and added the 
following to its OnTimer event:


=== code begin ===

  Writeln('Hello World ', fIndex);
  Inc(fIndex); // fIndex is a LongInt field of the form

=

Re: [fpc-pascal] fpHttpClient and Https support ?

2015-03-21 Thread fredvs
Excellent, thanks.

PS : Do you remember a old topic in Lazarus forum about uos and internet
audio streaming ?
(It was you who converts and helps me to install uos to GitHub).

Now uos does internet audio streaming !

=> https://github.com/fredvs/uos

Thanks Sergio.



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/fpHttpClient-and-Https-support-tp5721435p5721442.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fpHttpClient and Https support ?

2015-03-21 Thread fredvs
Ooops, in earlier topic => Thanks Silvio. ;-)

And, by the way, who may i thank for that excellent fpHttpClient.pas ?

Fre;D



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/fpHttpClient-and-Https-support-tp5721435p5721443.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] fpHttpClient and Https support ?

2015-03-21 Thread Michael Van Canneyt



On Sat, 21 Mar 2015, fredvs wrote:


Ooops, in earlier topic => Thanks Silvio. ;-)

And, by the way, who may i thank for that excellent fpHttpClient.pas ?


I plead guilty.

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


Re: [fpc-pascal] fpHttpClient and Https support ?

2015-03-21 Thread fredvs
> And, by the way, who may i thank for that excellent fpHttpClient.pas ?

> I plead guilty.

> Michael. 

Ha, so MANY THANKS Michael for your excellent. brilliant and easy to use 
fpHttpClient.pas

Fre;D




-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/fpHttpClient-and-Https-support-tp5721435p5721445.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] SVN Protocolo implementation

2015-03-21 Thread Antonio Sanguigni
Hello,

I would like to know if there is a OP implementation of SVN Protocol.

I know there is a LazSvnPkg but it is basde on TProcess and
communication with SVN bin. This would be my second chance so my
question.

I would prefer a OP implementation, even if very basic like import,
commit and update.

Thank you
Antonio

-- 
Antonio Sanguigni alias slapshot
--
Servizi informatici Windows e GNU/Linux- http://www.pieroni.biz
GioveLUG (Linux User Group) - http://www.giovelug.org
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] SVN Protocolo implementation

2015-03-21 Thread Mark Morgan Lloyd

Antonio Sanguigni wrote:

Hello,

I would like to know if there is a OP implementation of SVN Protocol.

I know there is a LazSvnPkg but it is basde on TProcess and
communication with SVN bin. This would be my second chance so my
question.

I would prefer a OP implementation, even if very basic like import,
commit and update.


I wonder whether libsvn would do what you want. Google suggests that 
Dmitry Boyarintsev was looking at this.


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

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread fredvs
Hello.

In Unix systems File Descriptor can be created with fpPipe(FDInput,
FDOutput).
Then FDInput/FDOutput may be used as file descriptors.
Ok, perfect.

But fpPipe is part of BaseUnix/Unix... 

So the question is:

How to create such of File Descriptor with Windows?...

Many thanks.

Fre;D


1) - Use fpPipe in BaseUnix/Unix to create a fifo.
2) - Create a THandleStream using the returned input value of fpPipe.
3) - Use mpg123_open_fd from the output value from fpPipe
4) - Use an instance of TfpHttpClient.Get(YourURL, AHandleStream) to
 retrieve the stream. 



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/File-Descriptor-in-Windows-tp5721448.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread Michael Van Canneyt



On Sat, 21 Mar 2015, fredvs wrote:


Hello.

In Unix systems File Descriptor can be created with fpPipe(FDInput,
FDOutput).
Then FDInput/FDOutput may be used as file descriptors.
Ok, perfect.

But fpPipe is part of BaseUnix/Unix...

So the question is:

How to create such of File Descriptor with Windows?...


See unit pipes, there is a platform-independennt call:
Function CreatePipeHandles (Var Inhandle,OutHandle : THandle; APipeBufferSize : 
Cardinal = 1024) : Boolean;

There is a second function which creates TStreams descendents.

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


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread fredvs
> Hello.
>
> In Unix systems File Descriptor can be created with fpPipe(FDInput,
> FDOutput).
> Then FDInput/FDOutput may be used as file descriptors.
> Ok, perfect.
>
> But fpPipe is part of BaseUnix/Unix...
>
> So the question is:
>
> How to create such of File Descriptor with Windows?...

>>See unit pipes, there is a platform-independennt call:
>>Function CreatePipeHandles (Var Inhandle,OutHandle : THandle;
APipeBufferSize : Cardinal = 1024) : Boolean;

>>There is a second function which creates TStreams descendents.

>>Michael. 

Ooops, so fast and so good !
I will try it now.
Write you later.

Many thanks.

Fre;D



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/File-Descriptor-in-Windows-tp5721448p5721450.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread fredvs
Hello.

Added Pipes in uses section.

Changed => AssignPipe(InHandle, FOutHandle);
Into => CreatePipeHandles (InHandle, FOutHandle, PipeBufferSize);  

Then in code =>
var
  Http: TFPHTTPClient;
  Output: THandleStream = nil;
  URL: String;
begin
  Http := TFPHTTPClient.Create(nil);
  Output := THandleStream.Create(FOutHandle);
  URL := FWantedURL;
   Http.RequestHeaders.Clear;
  Http.Get(URL, Output);

=> Perfect for Linux, compiles + web procedure runs perfectly (like using
fpPipe).

In Windows, same code compiles ok but when trying to run the web procedure,
Program gives that error =>

> An unespected error occurred
> File not open

? ;-(

Fre;D 
   



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/File-Descriptor-in-Windows-tp5721448p5721451.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread fredvs
Re-hello.

Tried with this too =>

Change =>  Output: THandleStream = nil; 
into  => Output: TOutputPipeStream = nil;

and

Change => Output := THandleStream.Create(FOutHandle);
into =>   Output:=TOutputPipeStream.Create (FOutHandle); 

=> Compiles + works perfect in Linux ;-)

=> Compiles ok but does not work on Windows ;-(
(file not open)

?

Thanks.

Fred;D



-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/File-Descriptor-in-Windows-tp5721448p5721452.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread Michael Van Canneyt



On Sat, 21 Mar 2015, fredvs wrote:


Hello.

Added Pipes in uses section.

Changed => AssignPipe(InHandle, FOutHandle);
Into => CreatePipeHandles (InHandle, FOutHandle, PipeBufferSize);

Then in code =>
var
 Http: TFPHTTPClient;
 Output: THandleStream = nil;
 URL: String;
begin
 Http := TFPHTTPClient.Create(nil);
 Output := THandleStream.Create(FOutHandle);
 URL := FWantedURL;
  Http.RequestHeaders.Clear;
 Http.Get(URL, Output);

=> Perfect for Linux, compiles + web procedure runs perfectly (like using
fpPipe).

In Windows, same code compiles ok but when trying to run the web procedure,
Program gives that error =>


An unespected error occurred
File not open


? ;-(


What do you do with the inHandle ?

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


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread fredvs
> What do you do with the inHandle ?
> Michael. 

It is used by mp123 mp3-decoder library.

=>function mpg123_open_fd(mph: Tmpg123_handle; fd: integer);

fp (file descriptor) := InHandle ;

It seems that InHandle as file descriptor does not work on Windows.
But in *nix system, it works.





-
Many thanks ;-)
--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/File-Descriptor-in-Windows-tp5721448p5721454.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Portable coroutines

2015-03-21 Thread Marco van de Voort
In our previous episode, Mark Morgan Lloyd said:
> Efficient implementation of coroutines requires CPU-specific code in the 
> RTL and possibly the compiler. However 
> http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html suggests a 
> way that coroutines can be implemented in a portable fashion in C, how 
> can this be done in Object Pascal?

Seems more an oddity than a system, but it relies heavily on preprocessor
and fallthrough case.

The preprocessor part can be done, just use whatever preprocessor
(maybe even cpp) and then haul the resulting code through fpc.

But there is no fallthrough case (and personally I think that is a good
thing)
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Mode Delphi and functions as parameters.

2015-03-21 Thread vfclists .
On 21 March 2015 at 10:04, Constantine Yannakopoulos 
wrote:

> On Fri, Mar 20, 2015 at 11:55 AM, Michael Schnell 
> wrote:
>
>> what to to if a function has no parameter and returns a value that is a
>> pointer to a function of exactly this type ?
>
>
> ​The logical thing for the compiler would be to assume that the
> programmer meant that a reference should be passed​. If the programmer
> wanted to invoke the function ans pass the result reference they should use
> empty parentheses aka "the invocation operator":
>
> CallFunction(SomeFunction); // passes a reference to SomeFunction.
> CallFunction(SomeFunction()); // passes the result of the invocation of
> SomeFunction.
>
> ​So no ambiguity, albeit a very subtle semantic difference that can easily
> produce bugs.​ But IMHO the "@" notation isn't much better either.
>
> PS: I tend to always use the "()" notation when invoking functions with no
> arguments so it will be clear to a future reader that I'm invoking a
> function and not assigning some variable. Makes a difference with poorly
> named functions (not starting with a verb):
>
> ADate := Date;
> ADate := Date();
>
>
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>

Compilers should not assume. Programmers should be explicit about what they
want.
Assumptions based on ambiguous semantics are an unending source of problems.

-- 
Frank Church

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

Re: [fpc-pascal] Where is the 'write' function defined and how is it different from 'writeln'?

2015-03-21 Thread vfclists .
On 21 March 2015 at 11:35, Sven Barth  wrote:

> On 21.03.2015 11:13, vfclists . wrote:
>
>>
>>
>> On 20 March 2015 at 20:54, Sven Barth > > wrote:
>>
>> On 20.03.2015 21:18, vfclists . wrote:
>>
>>
>>
>> On 20 March 2015 at 19:34, Sven Barth
>> mailto:pascaldra...@googlemail.com>
>> > >> wrote:
>>
>>  Am 20.03.2015 19:19 schrieb "vfclists ."
>> mailto:vfcli...@gmail.com>
>>  >>:
>>
>>
>>
>> snip
>>
>> How do you ensure own implementation overrides the system's
>> implementation, does the compiler take care of that
>> automatically, or
>> will you have to name your function differently?
>>
>>
>> There is no need to ensure that. Here is an example:
>>
>> === code begin ===
>>
>> var
>>f, oldout: TextFile;
>> begin
>>Writeln('Hello Output as StdOut');
>>
>>oldout := Output;
>>
>>Assign(Output, 'test.txt');
>>Rewrite(Output);
>>
>>Writeln('Hello Output as file');
>>
>>Close(f);
>>
>>Output := oldout;
>>
>>Writeln('Hello Output as StdOut again');
>> end.
>>
>> === code end ===
>>
>> To see how such a TextFile is implemented you can take a look at
>> unit StreamIO which is part of FPC's units.
>>
>> (Though I wonder why "Assign(f, 'test.txt'); Output := f;
>> Writeln('Hello Output as file');" does not work :/ )
>>
>> Regards,
>> Sven
>>
>> _
>> fpc-pascal maillist  - fpc-pascal@lists.freepascal.__org
>> 
>> http://lists.freepascal.org/__cgi-bin/mailman/listinfo/fpc-__pascal
>> 
>>
>>
>> I need to get the output of a program which uses a lot of Write and
>> Writeln commands into the GUI in realtime, by that I not having to
>> output it to a text file and reading it afterwards, but by capturing the
>> output of each Write command into a variable and displaying it in the
>> GUI immediately.
>>
>> If each Write or Writeln could trigger an event, I could use the event
>> to capture the output. My other option is to replace the calls to write
>> with my own function, but Write has different number of call parameters
>> and it may require as many variants of the function as are used in the
>> program, assuming that the call syntax is regular, not something like
>> this one - write(JSValToDouble(cx,pom^)):1:scale).
>>
>
> The usage of a text file was merely an example. As I said there already is
> the possibility to use a TStream provided by FPC. But since I'm nice here
> you also have an example for a TMemo, I'm sure you can adjust that for your
> needs:
>
> === code begin ===
>
> resourcestring
>   SErrNilMemo = 'Memo is nil';
>
> type
>   PMemo = ^TMemo;
>
> function GetMemo(var F: TTextRec): TMemo;
> begin
>   Result:=PMemo(@F.Userdata)^;
> end;
>
> function MemoWrite(var F: TTextRec): LongInt;
> var
>   s: String;
> begin
>   Result := 0;
>   with F do
> if BufPos > 0 then
>   try
> SetLength(s, BufPos);
> Move(BufPtr^, s[1], BufPos);
> GetMemo(F).SelText := s;
> BufPos:=0;
>   except
> Result:=101;
>   end;
> end;
>
>
> function MemoClose(var F: TTextRec): LongInt;
> begin
>   Result := 0;
> end;
>
> function MemoOpen(var F: TTextRec): LongInt;
> begin
>   Result := 0;
>   with F do begin
> BufPos:=0;
> Bufend:=0;
> case Mode of
>   fmInput: begin
> Result := 104;
>   end;
>   fmOutput, fmAppend: begin
> InOutFunc := @MemoWrite;
> FlushFunc := @MemoWrite;
> if Mode = fmAppend then
>   Try
> with GetMemo(F) do begin
>   SelStart := Length(Text);
> end;
>   except
> Result := 156;
>   end;
> end else begin
>   GetMemo(F).Clear;
> end;
> end;
> end;
> end;
>
> procedure AssignMemo(var F: Text; aMemo: TMemo);
> var
>   e: EInoutError;
> begin
>   if not Assigned(aMemo) then begin
> E:=EInOutError.Create(SErrNilMemo);
> E.ErrorCode:=6;
> Raise E;
>   end;
>   with TTextRec(F) do begin
> OpenFunc := @MemoOpen;
> CloseFunc := @MemoClose;
> case DefaultTextLineBreakStyle Of
>   tlbsLF:
> TextRec(f).LineEnd := #10;
>   tlbsCRLF:
> TextRec(f).LineEnd := #13#10;
>   tlbsCR:
> TextRec(f).LineEnd := #13;
> end;
> PMemo(@UserData)^ := aMemo;
> Mode := fmClosed;
> BufSize := SizeOf(Buffer);
> BufPtr := @Buffer;
> Name[0] := #0;
>   end;
> end;
>
> === code end ===
>
> To use it you should use the following code (for example in FormCreate):
>
> === code begin ===
>
>   fOldOutput := Outp

Re: [fpc-pascal] Where is the 'write' function defined and how is it different from 'writeln'?

2015-03-21 Thread Jonas Maebe
On 22/03/15 00:11, vfclists . wrote:
> In case of wanting to use different Text objects is it possible to
> prefix the Write command with the Text e.g Write(TextObject,
> 'outputtext')? Do Write and WriteLn support something like that?

http://www.freepascal.org/docs-html/rtl/system/write.html
http://www.freepascal.org/docs-html/rtl/system/writeln.html


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


Re: [fpc-pascal] Where is the 'write' function defined and how is it different from 'writeln'?

2015-03-21 Thread Sven Barth

On 22.03.2015 00:11, vfclists . wrote:

Is the Text object the Write is using global for the whole program or
thread, ie all Writes will go to that Text object until it is reverted
back to the default?


The variables Output, Input and StdErr are thread local so you need to 
set them up for each thread.



In case of wanting to use different Text objects is it possible to
prefix the Write command with the Text e.g Write(TextObject,
'outputtext')? Do Write and WriteLn support something like that?


As I already wrote Write('outputtext') is essentially the same as 
Write(Output, 'outputtext') so you can of course write 
Write(SomeOtherFile, 'outputtext')


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


Re: [fpc-pascal] File Descriptor in Windows ?

2015-03-21 Thread Andrew Haines
Check for writeln's in the htmlthread unit you added.

On March 21, 2015 6:23:44 PM EDT, fredvs  wrote:
>> What do you do with the inHandle ?
>> Michael. 
>
>It is used by mp123 mp3-decoder library.
>
>=>function mpg123_open_fd(mph: Tmpg123_handle; fd: integer);
>
>fp (file descriptor) := InHandle ;
>
>It seems that InHandle as file descriptor does not work on Windows.
>But in *nix system, it works.
>
>
>
>
>
>-
>Many thanks ;-)
>--
>View this message in context:
>http://free-pascal-general.1045716.n5.nabble.com/File-Descriptor-in-Windows-tp5721448p5721454.html
>Sent from the Free Pascal - General mailing list archive at Nabble.com.
>___
>fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
>http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal