Re: [fpc-pascal] Ethernet Relays

2020-09-06 Thread James Richters via fpc-pascal
I've been using simpleget to control ethernet relays like this:
S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');

But if the IP address does not exist on the network I get this error:

An unhandled exception occurred at $000100032A4A:
ESocketError: Connection to 10.10.01.01:80 timed out.

And my program terminates.  Is there some way I can capture this error with my 
program so I can just put up a message about the problem and keep running?

Is there a way to change the amount of time before the timeout?

James 

-Original Message-
From: fpc-pascal  On Behalf Of James 
Richters
Sent: Monday, May 25, 2020 8:19 AM
To: 'FPC-Pascal users discussions' 
Subject: Re: [fpc-pascal] Ethernet Relays

Thank you Michael, I would have really overcomplicated that, glad I asked

James

-Original Message-
From: fpc-pascal  On Behalf Of Michael 
Van Canneyt
Sent: Monday, May 25, 2020 6:54 AM
To: ja...@productionautomation.net; FPC-Pascal users discussions 

Subject: Re: [fpc-pascal] Ethernet Relays



On Mon, 25 May 2020, James Richters wrote:

> Thanks! 
>
> Is there some convenient way to get the HTML into a Tstringlist?

Yes. Simpleget is overloaded to accept a tstrings:

L:=TstringList.Create;
try
TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/01',L);
finally
   L.Free;
end;

Michael.
>
> James
>
> -Original Message-
> From: fpc-pascal  On Behalf 
> Of Michael Van Canneyt
> Sent: Monday, May 25, 2020 4:47 AM
> To: ja...@productionautomation.net; FPC-Pascal users discussions 
> 
> Cc: 'Ched' 
> Subject: Re: [fpc-pascal] Ethernet Relays
>
>
>
> On Sun, 24 May 2020, James Richters wrote:
>
>> I got this working, thanks for the advice Ched,
>>
>> Here's my test program:
>> uses  fphttpclient;
>> Begin
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/01');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/03');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/05');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/07');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/43');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/09');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/11');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/13');
>> TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
>> End.
>>
>> I have to give it a command to go the next page for some reason or 
>> relays
>> 5-8 won't work...  so now I'm wondering if there is a way I can 
>> retrieve the data that is normally displayed in my browser to I can 
>> see what page number I'm on,  I could also then check the status of 
>> the relays as well by analyzing what I read.
>
> Simpleget is a function that returns the page:
>
> S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
>
> S will contain the page of HTML.
>
> If you need to send a command, you'll probably need to use
> SimplePost()
>
> Michael.
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org 
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

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


Re: [fpc-pascal] Ethernet Relays

2020-09-06 Thread Michael Van Canneyt via fpc-pascal



On Sun, 6 Sep 2020, James Richters via fpc-pascal wrote:


I've been using simpleget to control ethernet relays like this:
S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');

But if the IP address does not exist on the network I get this error:

An unhandled exception occurred at $000100032A4A:
ESocketError: Connection to 10.10.01.01:80 timed out.

And my program terminates.  Is there some way I can capture this error
with my program so I can just put up a message about the problem and keep
running?


Yes, catch the ESocketError in a try..except:

Try
  S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
except
  On E: ESocketError do
Writeln('Could not connect to server');
end;


Is there a way to change the amount of time before the timeout?


Yes, but then you need to create an instance, i.e. the Simple* commands
won't do that for you:

Instead, it will look like this:

uses fphttpclient;

Var
  C : TFPHTTPClient;

begin
  C:=TFPHTTPClient.Create(Nil);
  try
 try
   C.ConnectTimeout:=10; // Or whatever you think is good
   C.Get('http://10.10.01.01/3/15');
 except
   On E: ESocketError do
 Writeln('Could not connect to server');
 end;
  finally
C.Free;
  end; 
end;


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


[fpc-pascal] Thread problem

2020-09-06 Thread Paul Renaud via fpc-pascal
IHello,

I'm having a problem with the OS/2 version of the compiler.

This simplified version of my program keeps generating an exception
when compiled and run in EComStation 1.2, OS/2 versions 4.5 and 4 
but runs fine when compiled for Windows. 

Program Test1( Input, Output );

{$S+}

  Const
    StackSize = 100;
    
    Max_Array = 5000;

  Type
    Data_Array = packed array[ 0 .. Max_Array ] of LongInt;

  Function MyThread( P: Pointer ): PtrInt;
    Var
  Data: Data_Array;
  Indexer: LongInt;
    Begin
  MyThread := 0;
  For Indexer := 1 to Max_Array do
    Data[ Indexer ] := 0;
    End;  
    
  Var
    Handle: LongWord;
    My_Result: LongInt;
  Begin
    WriteLn( 'Test1 starting' );
    My_Result := BeginThread( @MyThread, Nil, Handle, StackSize );

    My_Result := WaitForThreadTerminate( Handle, 0 );
    WriteLn( 'Test1 finished' );
  End.

The error generated is...

SYS1808:
The process has stopped.  The sofware diagnostic 
code (exception code) is  0005.

the command I used to compile it is:

fpc Test1.pas -Se -gl

This exception appears to be generated before my thread gets control,
so I can't install my own exception handlers to intercept it.

Any help would be appreciated.
Thanks,
Paul.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Thread problem

2020-09-06 Thread Travis Siegel via fpc-pascal

I'm not sure it works properly on windows.

When I modify this to start two threads, and print out messages based on 
their start/stop times, as well as a message inside the thread, I get 
both ending messages before I get only a single printout from within the 
threaded function.  This seems to indicate windows isn't starting two 
threads, though I don't have a clue how to verify this.


Just thought I'd add fuel to the fire here. :)


On 9/6/2020 1:00 PM, Paul Renaud via fpc-pascal wrote:

I
Hello,

I'm having a problem with the OS/2 version of the compiler.

This simplified version of my program keeps generating an exception
when compiled and run in EComStation 1.2, OS/2 versions 4.5 and 4
but runs fine when compiled for Windows.

Program Test1( Input, Output );

{$S+}

  Const
    StackSize = 100;

    Max_Array = 5000;

  Type
    Data_Array = packed array[ 0 .. Max_Array ] of LongInt;

  Function MyThread( P: Pointer ): PtrInt;
    Var
  Data: Data_Array;
  Indexer: LongInt;
    Begin
  MyThread := 0;
  For Indexer := 1 to Max_Array do
    Data[ Indexer ] := 0;
    End;

  Var
    Handle: LongWord;
    My_Result: LongInt;
  Begin
    WriteLn( 'Test1 starting' );
    My_Result := BeginThread( @MyThread, Nil, Handle, StackSize );

    My_Result := WaitForThreadTerminate( Handle, 0 );
    WriteLn( 'Test1 finished' );
  End.

The error generated is...

SYS1808:
The process has stopped.  The sofware diagnostic
code (exception code) is  0005.

the command I used to compile it is:

fpc Test1.pas -Se -gl

This exception appears to be generated before my thread gets control,
so I can't install my own exception handlers to intercept it.

Any help would be appreciated.
Thanks,
Paul.


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


[fpc-pascal] TFPObjectlist example

2020-09-06 Thread James Richters via fpc-pascal
Am I correct that TFPObjectlist is kind of like Tstringlist, except instead of 
creating and array of strings, it creates an array of objects?

I'm wanting to do something like that but I don't know how to define the 
object.. I'm guessing it would be something like a record

I'm wanting to end up with a list of records like:
Type
   test = record
  Port :String;
  Size :Byte;
  Status   :Word;
   End;

Does anyone have an example of how to use TFPObjectlist?  

James

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


Re: [fpc-pascal] Ethernet Relays

2020-09-06 Thread James Richters via fpc-pascal
Thanks Michael,  I'll give it a try

James
-Original Message-
From: fpc-pascal  On Behalf Of Michael 
Van Canneyt via fpc-pascal
Sent: Sunday, September 6, 2020 11:12 AM
To: James Richters ; FPC-Pascal users 
discussions 
Cc: Michael Van Canneyt 
Subject: Re: [fpc-pascal] Ethernet Relays



On Sun, 6 Sep 2020, James Richters via fpc-pascal wrote:

> I've been using simpleget to control ethernet relays like this:
> S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
>
> But if the IP address does not exist on the network I get this error:
>
> An unhandled exception occurred at $000100032A4A:
> ESocketError: Connection to 10.10.01.01:80 timed out.
>
> And my program terminates.  Is there some way I can capture this error 
> with my program so I can just put up a message about the problem and 
> keep running?

Yes, catch the ESocketError in a try..except:

Try
   S:=TFPHTTPCLIENT.SIMPLEGET('http://10.10.01.01/3/15');
except
   On E: ESocketError do
 Writeln('Could not connect to server'); end;

> Is there a way to change the amount of time before the timeout?

Yes, but then you need to create an instance, i.e. the Simple* commands won't 
do that for you:

Instead, it will look like this:

uses fphttpclient;

Var
   C : TFPHTTPClient;

begin
   C:=TFPHTTPClient.Create(Nil);
   try
  try
C.ConnectTimeout:=10; // Or whatever you think is good
C.Get('http://10.10.01.01/3/15');
  except
On E: ESocketError do
  Writeln('Could not connect to server');
  end;
   finally
 C.Free;
   end;
end;

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

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


Re: [fpc-pascal] TFPObjectlist example

2020-09-06 Thread Ryan Joseph via fpc-pascal


> On Sep 7, 2020, at 6:07 AM, James Richters via fpc-pascal 
>  wrote:
> 
> Does anyone have an example of how to use TFPObjectlist?  

It just frees objects that are removed from the list (or when the list is 
freed).

list:= TFPObjectlist.Create;
list.Add(TObject.Create);
list.Free;

in that example the object added to the list won't leak memory but it will be 
freed when the list itself is freed.

or

list:= TFPObjectlist.Create;
list.Add(TObject.Create);
list.Delete(0);

will also not leak memory.

Regards,
Ryan Joseph

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


Re: [fpc-pascal] String literals and code page of .pas source file

2020-09-06 Thread LacaK via fpc-pascal

Hello Jonas,

attached simple Lazarus compilable project (one Form).

...
type
  String1250 = type AnsiString(1250);

const
  c2: AnsiString = 'áéíóčž';
  c3: WideString = 'áéíóčž';
  c4: String1250 = 'áéíóčž';

{ TForm1 }

procedure TForm1.FormShow(Sender: TObject);
begin
  label1.Caption:='áéíóčž'; // FAIL
  label2.Caption:=c2;   // FAIL
  label3.Caption:=c3;   // OK
  label4.Caption:=c4;   // FAIL
end;

TIA

-Laco.



I would like to have source file in Windows-1250 encoding, where are
stored literal strings like 'áéíóčž' in Windows-1250 encoding (I share
this one file between FPC/Lazarus and Delphi 7). Windows-1250 is also
ANSI code page of my Windows OS. In source file I have:

{$IFDEF FPC}
   {$CODEPAGE cp1250}
{$ENDIF}

and in Lazarus I have set: File settings / Encoding / CP1250
(at this point in .pas file are all characters correctly encoded in
Windows-1250 code page)

When I compile application and run it, string literals (characters with
accents) are not preserved.
Is there way how to get it working?

The attached program uses the same environment as Lazarus
(DefaultSystemCodePage forced to UTF-8) and prints the string correctly
for me (under Mac OS X).

Please always provide a compilable program when reporting issues.


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