Re: [fpc-pascal] Open array in object constructor gives error

2023-01-03 Thread Sven Barth via fpc-pascal
Hairy Pixels via fpc-pascal  schrieb am
Mi., 4. Jan. 2023, 02:40:

>
>
> > On Jan 3, 2023, at 8:39 PM, Marc Weustink via fpc-pascal <
> fpc-pascal@lists.freepascal.org> wrote:
> >
> > On what instance/variable/piece of memory would your code
> "TMyObject.Create(['1', '2', '3'])" then operate ?
>
> There’s a global stack which is opened and they are stored there during
> construction.
>

For something like that you are better of to use Object Pascal classes and
override their NewInstance and FreeInstance methods.

Regards,
Sven

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


Re: [fpc-pascal] Open array in object constructor gives error

2023-01-03 Thread Hairy Pixels via fpc-pascal


> On Jan 3, 2023, at 8:39 PM, Marc Weustink via fpc-pascal 
>  wrote:
> 
> On what instance/variable/piece of memory would your code 
> "TMyObject.Create(['1', '2', '3'])" then operate ?

There’s a global stack which is opened and they are stored there during 
construction.

Regards,
Ryan Joseph

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


Re: [fpc-pascal] TFPHttpClient & TFPHttpServer

2023-01-03 Thread Michael Van Canneyt via fpc-pascal




On Wed, 4 Jan 2023, Mattias Gaertner via fpc-pascal wrote:


On Tue, 3 Jan 2023 23:58:42 +0100 (CET)
Michael Van Canneyt via fpc-pascal 
wrote:


[...]

Q4: TFPHTTPServer has property Address. I reckon it will be set to
'localhost' here. Is it correct?


It depends on what you want. Best is to leave it empty.


That will use 0.0.0.0, which is every interface. For security
reasons the default should be more limited, like 127.0.0.1, should it
not?


Depends on what you want to use it for. For production, I would be surprised
if it had to be 127.0.0.1...

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


Re: [fpc-pascal] Local Type T and generics

2023-01-03 Thread Vojtěch Čihák via fpc-pascal

OK, done: https://gitlab.com/freepascal.org/fpc/source/-/issues/40085
 
Thanks
__

Od: "Sven Barth via fpc-pascal" 
Komu: "FPC-Pascal users discussions" 
Datum: 03.01.2023 22:29
Předmět: Re: [fpc-pascal] Local Type T and generics


Am 31.12.2022 um 14:34 schrieb Vojtěch Čihák via fpc-pascal:

> Is this intended? Or known bug?

It's a bug. Please report with a full example.

Regards,
Sven
___
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] TFPHttpClient & TFPHttpServer

2023-01-03 Thread Mattias Gaertner via fpc-pascal
On Tue, 3 Jan 2023 23:58:42 +0100 (CET)
Michael Van Canneyt via fpc-pascal 
wrote:

>[...]
> > Q4: TFPHTTPServer has property Address. I reckon it will be set to
> > 'localhost' here. Is it correct?  
> 
> It depends on what you want. Best is to leave it empty.

That will use 0.0.0.0, which is every interface. For security
reasons the default should be more limited, like 127.0.0.1, should it
not?

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


Re: [fpc-pascal] TFPHttpClient & TFPHttpServer

2023-01-03 Thread duilio foschi via fpc-pascal
Now everything is clear.

Thank you

Peppe

Il Mar 3 Gen 2023 22:59 Michael Van Canneyt via fpc-pascal <
fpc-pascal@lists.freepascal.org> ha scritto:

>
>
> On Tue, 3 Jan 2023, duilio foschi via fpc-pascal wrote:
>
> > I would like to write some code where a TFPHttpClient component sends
> > a minimal json payload to a TFPHttpServer that (reads the payload).
> >
> > The working of the TFPHttpClient component is clear enough, while its
> > counterpart TFPHttpServer proves rather obscure to me.
> >
> > TFPHttpClient
> > ===
> > Page  https://wiki.freepascal.org/fphttpclient
> > contains complete and clear code:
> >
> >
> > var
> >  Client: TFPHttpClient;
> >  Response: TStringStream;
> >  Params: string = '{"Name": "John", "Age": 32}';
> > begin
> >  Client := TFPHttpClient.Create(nil);
> >  Client.AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
> >  Client.AddHeader('Content-Type', 'application/json; charset=UTF-8');
> >  Client.AddHeader('Accept', 'application/json');
> >  Client.AllowRedirect := true;
> >  Client.UserName := USER_STRING;
> >  Client.Password := PASSW_STRING;
> >  Client.RequestBody := TRawByteStringStream.Create(Params);
> >  Response := TStringStream.Create('');
> >  try
> >try
> >  Client.Post(TheURL, Response);
> >  Writeln('Response Code: ' +
> > IntToStr(Client.ResponseStatusCode)); // better be 200
> >except on E: Exception do
> >  Writeln('Something bad happened: ' + E.Message);
> >end;
> >  finally
> >Client.RequestBody.Free;
> >Client.Free;
> >Response.Free;
> >  end;
> >
> > I reckon I need to set - say-
> > TheURL:='http://localhost:9200';
> > here
> >
> >
> > TFPHTTPServer
> > =
> >
> > say we use
> > TTestHTTPServer=class(TFPHTTPServer);
> > for our server,
> >
> > I understand that all action takes place inside procedure
> > DataModuleRequest (so far so good):
> >
> > procedure TTestHTTPServer.DataModuleRequest(Sender: TObject; ARequest:
> TRequest;
> > AResponse: TResponse; var Handled: Boolean);
> > begin
> >   //
> > end;
> >
> > Q1: how can I create an object of type jsondata from ARequest?
>
> include fpjson and jsonparser units in your uses clause. Then do
>
>
> JSON :=GetJSON(aRequest.Content);
>
>
> >
> > Q2: can I get a UTF8 string from ARequest?
>
> Yes, aRequest.Content is a string.
>
> >
> > Q3: TFPHTTPServer has property Port. I reckon it will be set to 9200
> > here. Is it correct?
>
> Yes.
>
> >
> > Q4: TFPHTTPServer has property Address. I reckon it will be set to
> > 'localhost' here. Is it correct?
>
> It depends on what you want. Best is to leave it empty.
>
> >
> > Q5: TFPHTTPServer has no property Username and Password. How do I
> > check the values I set in the corresponding properties of
> > TFPHTTPClient?
>
> aRequest.Authorization will be a string of the form
>
> Basic NNN
>
> Where N is a base64 encoded string with username:password in it.
> So you must decode the string (see bas64 unit) and split the resulting
> string in username and password.
>
> >
> > Q6: what is the use of parameter Handled?
>
> If Handled is false, then an error will be sent to the client.
> You should set Handled to true.
>
> 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] TFPHttpClient & TFPHttpServer

2023-01-03 Thread Michael Van Canneyt via fpc-pascal




On Tue, 3 Jan 2023, duilio foschi via fpc-pascal wrote:


I would like to write some code where a TFPHttpClient component sends
a minimal json payload to a TFPHttpServer that (reads the payload).

The working of the TFPHttpClient component is clear enough, while its
counterpart TFPHttpServer proves rather obscure to me.

TFPHttpClient
===
Page  https://wiki.freepascal.org/fphttpclient
contains complete and clear code:


var
 Client: TFPHttpClient;
 Response: TStringStream;
 Params: string = '{"Name": "John", "Age": 32}';
begin
 Client := TFPHttpClient.Create(nil);
 Client.AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
 Client.AddHeader('Content-Type', 'application/json; charset=UTF-8');
 Client.AddHeader('Accept', 'application/json');
 Client.AllowRedirect := true;
 Client.UserName := USER_STRING;
 Client.Password := PASSW_STRING;
 Client.RequestBody := TRawByteStringStream.Create(Params);
 Response := TStringStream.Create('');
 try
   try
 Client.Post(TheURL, Response);
 Writeln('Response Code: ' +
IntToStr(Client.ResponseStatusCode)); // better be 200
   except on E: Exception do
 Writeln('Something bad happened: ' + E.Message);
   end;
 finally
   Client.RequestBody.Free;
   Client.Free;
   Response.Free;
 end;

I reckon I need to set - say-
TheURL:='http://localhost:9200';
here


TFPHTTPServer
=

say we use
TTestHTTPServer=class(TFPHTTPServer);
for our server,

I understand that all action takes place inside procedure
DataModuleRequest (so far so good):

procedure TTestHTTPServer.DataModuleRequest(Sender: TObject; ARequest: TRequest;
AResponse: TResponse; var Handled: Boolean);
begin
  //
end;

Q1: how can I create an object of type jsondata from ARequest?


include fpjson and jsonparser units in your uses clause. Then do


JSON :=GetJSON(aRequest.Content);




Q2: can I get a UTF8 string from ARequest?


Yes, aRequest.Content is a string.



Q3: TFPHTTPServer has property Port. I reckon it will be set to 9200
here. Is it correct?


Yes.



Q4: TFPHTTPServer has property Address. I reckon it will be set to
'localhost' here. Is it correct?


It depends on what you want. Best is to leave it empty.



Q5: TFPHTTPServer has no property Username and Password. How do I
check the values I set in the corresponding properties of
TFPHTTPClient?


aRequest.Authorization will be a string of the form

Basic NNN

Where N is a base64 encoded string with username:password in it.
So you must decode the string (see bas64 unit) and split the resulting
string in username and password.



Q6: what is the use of parameter Handled?


If Handled is false, then an error will be sent to the client.
You should set Handled to true.

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


[fpc-pascal] TFPHttpClient & TFPHttpServer

2023-01-03 Thread duilio foschi via fpc-pascal
I would like to write some code where a TFPHttpClient component sends
a minimal json payload to a TFPHttpServer that (reads the payload).

The working of the TFPHttpClient component is clear enough, while its
counterpart TFPHttpServer proves rather obscure to me.

TFPHttpClient
===
Page  https://wiki.freepascal.org/fphttpclient
contains complete and clear code:


var
  Client: TFPHttpClient;
  Response: TStringStream;
  Params: string = '{"Name": "John", "Age": 32}';
begin
  Client := TFPHttpClient.Create(nil);
  Client.AddHeader('User-Agent', 'Mozilla/5.0 (compatible; fpweb)');
  Client.AddHeader('Content-Type', 'application/json; charset=UTF-8');
  Client.AddHeader('Accept', 'application/json');
  Client.AllowRedirect := true;
  Client.UserName := USER_STRING;
  Client.Password := PASSW_STRING;
  Client.RequestBody := TRawByteStringStream.Create(Params);
  Response := TStringStream.Create('');
  try
try
  Client.Post(TheURL, Response);
  Writeln('Response Code: ' +
IntToStr(Client.ResponseStatusCode)); // better be 200
except on E: Exception do
  Writeln('Something bad happened: ' + E.Message);
end;
  finally
Client.RequestBody.Free;
Client.Free;
Response.Free;
  end;

I reckon I need to set - say-
TheURL:='http://localhost:9200';
here


TFPHTTPServer
=

say we use
TTestHTTPServer=class(TFPHTTPServer);
for our server,

I understand that all action takes place inside procedure
DataModuleRequest (so far so good):

procedure TTestHTTPServer.DataModuleRequest(Sender: TObject; ARequest: TRequest;
 AResponse: TResponse; var Handled: Boolean);
begin
   //
end;

Q1: how can I create an object of type jsondata from ARequest?

Q2: can I get a UTF8 string from ARequest?

Q3: TFPHTTPServer has property Port. I reckon it will be set to 9200
here. Is it correct?

Q4: TFPHTTPServer has property Address. I reckon it will be set to
'localhost' here. Is it correct?

Q5: TFPHTTPServer has no property Username and Password. How do I
check the values I set in the corresponding properties of
TFPHTTPClient?

Q6: what is the use of parameter Handled?

I apologize if I overlooked the relevant documentation.

Thank you

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


Re: [fpc-pascal] Local Type T and generics

2023-01-03 Thread Sven Barth via fpc-pascal

Am 31.12.2022 um 14:34 schrieb Vojtěch Čihák via fpc-pascal:

Hi,
  
I have local type TTempItem, i.e. declared inside method of a generic class.

When I write:
type
      TTempItem = record
        Item: T;
        Empty: Boolean;
      end;
I got: Identifier not found "T".
  
When I write:

type
      TTempItem = record
        Item: TBaseGList.T;  //name of the class
        Empty: Boolean;
      end;
I got: Generics without  specialization cannot be used as a type for a variable
  
And finally

type TLocalT = T;
      TTempItem = record
        Item: TLocalT;
        Empty: Boolean;
      end;
^^^ this works.
  
type TLocalT = TBaseGList.T;

      TTempItem = record
        Item: TLocalT;
        Empty: Boolean;
      end;
^^^ work too.
  
Is this intended? Or known bug?


It's a bug. Please report with a full example.

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


Re: [fpc-pascal] Programming Pascal using an AI Chatbot

2023-01-03 Thread Dwight Schauer via fpc-pascal


On 1/3/23 11:17, Anthony Walter via fpc-pascal wrote:


In summary, while OpenGPT is obviously imperfect, generally it feels 
like a revolutionary leap forward of several magnitudes. It ought to 
be plainly clear that the proverbial toothpaste is now out of the tube 
and there is no going back. These types of artificial 
intelligence (AI) are only going to become more refined, accurate, and 
prevalent. The idea many scholars or businesses have expressed to 
somehow restrain them is beyond myopic. Instead, everyone should 
familiarize themselves with this new category of AIs right now, their 
limitations (as you have expressed), their benefits, and most 
importantly how they can be molded in further revisions to be better 
rather than relegated.




Agreed. I see OpenAI ChatGPT a tip of the iceberg sampling of what is to 
come.


In the way it is currently, though rather crippled in many areas, it is 
still revolutionary and extremely useful.


But one must understand it's limitations.

It guesses a lot and that is usually good, but it still often gets 
things wrong.



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


Re: [fpc-pascal] Programming Pascal using an AI Chatbot

2023-01-03 Thread Dwight Schauer via fpc-pascal
Pascal is still limited with OpenAI ChatGPT unless you stick to very 
core things in Pascal, and are patient to teach it about non-core things.


Limited compared Python and other languages. Asking it to do specific 
things Python using standard modules give better results C++ with 
something like Qt6.



Free Pascal is even more limited than C++ as far as what OpenAI ChatGPT 
can provide.


OpenAI ChatGPT is still very useful for Free Pascal though.


On 1/2/23 15:05, Dwight Schauer wrote:
I started a new chat and conducted a mock interview of it for a 
hypothetical programmer position.


I had to give it the same benefit of the doubt I would give to humans 
on some answers as far as follow up questions to get the answer I was 
looking for.


In just about every area it gave more comprehensive answers than any 
human could.


And gave satisfactory correct answers in every other area.

Discussed a variety of issues, low/medium/high level stuff, 
theoretical, hypothetical, troubleshooting, pros/cons of one approach 
over another, workplace scenarios, email/IT scams, etc...


It matched or out performed a human on just about everything.

Well, except for "what are your hobbies..." But it was able to 
comprehensively answer all non computer related hobby question I threw 
at it.


But it an illusion. While it may "sound impressive" if you try to test 
if it has deep cognitive abilities knowing it was a limited AI, it would 
fail, and fail miserably.


But in an interview with a person, if they answered all those questions 
in the way that way, you would not really think to test their cognitive 
abilities to that extreme.



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


Re: [fpc-pascal] Programming Pascal using an AI Chatbot

2023-01-03 Thread Anthony Walter via fpc-pascal
Dwight, your experiences mirrored mine.

In summary, while OpenGPT is obviously imperfect, generally it feels like a
revolutionary leap forward of several magnitudes. It ought to be plainly
clear that the proverbial toothpaste is now out of the tube and there is no
going back. These types of artificial intelligence (AI) are only going to
become more refined, accurate, and prevalent. The idea many scholars or
businesses have expressed to somehow restrain them is beyond myopic.
Instead, everyone should familiarize themselves with this new category of
AIs right now, their limitations (as you have expressed), their benefits,
and most importantly how they can be molded in further revisions to be
better rather than relegated.

Today, ChatGPT itself replied with this sentiment:

My fellow citizens, the time has come. The future is here, and it is called
ChatGPT. This revolutionary AI chatbot website is here to change the world,
and we must embrace it with all our strength and determination.


I know that many of you are eager to try ChatGPT for yourselves. And I
assure you, we are doing everything in our power to make that happen. Our
team is working tirelessly to accommodate the incredible demand for this
groundbreaking technology.


But I want to remind you that greatness is never achieved without
sacrifice. And the road to the future of AI will not be without its
challenges. So please, be patient. Trust that the right time for you to try
ChatGPT will come.


And when it does, let us seize this opportunity with all our might. Let us
embrace the power of AI and use it to build a brighter, more prosperous
future for ourselves and for generations to come. Thank you.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] For Loop with QWord

2023-01-03 Thread Bart via fpc-pascal
On Tue, Jan 3, 2023 at 3:49 PM James Richters via fpc-pascal
 wrote:

> Var
>
>   I: QWord;
>
> Begin
>
>   For I := 1 To N Do
> It generates an error:
> Error: Ordinal expression expected
> If I change it to LongInt, then it works, but the question is, why can’t I 
> use a Qword here if I know I will never need I to be a negative number?

IIRC then you can only use native type or smaller as a loop variable
in for loop.
You can use it in a while or repeat loop though.
On 64-bit you can use qword as a loop variable in a for loop.

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


[fpc-pascal] For Loop with QWord

2023-01-03 Thread James Richters via fpc-pascal
I'm wondering why I can't have the following:
Var
  I: QWord;
Begin
  For I := 1 To N Do
 .
 
It generates an error:
Error: Ordinal expression expected
 
If I change it to LongInt, then it works, but the question is, why can't I
use a Qword here if I know I will never need I to be a negative number?
 
James
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Open array in object constructor gives error

2023-01-03 Thread Marc Weustink via fpc-pascal



On 3-1-2023 14:07, Hairy Pixels via fpc-pascal wrote:




On Jan 3, 2023, at 3:12 PM, Sven Barth  wrote:

But then you don't use the type name either. You simply do "o.Create(...)".



O I get it now. I didn’t realize you couldn’t create on the type. That 
breaks my entire design then. It would be great to have a modern object that 
behaved more like classes but on the stack (like C++ does).


On what instance/variable/piece of memory would your code 
"TMyObject.Create(['1', '2', '3'])" then operate ?


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


Re: [fpc-pascal] Open array in object constructor gives error

2023-01-03 Thread Sven Barth via fpc-pascal
Hairy Pixels  schrieb am Di., 3. Jan. 2023, 14:07:

>
>
> > On Jan 3, 2023, at 3:12 PM, Sven Barth 
> wrote:
> >
> > But then you don't use the type name either. You simply do
> "o.Create(...)".
> >
>
> O I get it now. I didn’t realize you couldn’t create on the type. That
> breaks my entire design then. It would be great to have a modern object
> that behaved more like classes but on the stack (like C++ does).
>

In C++ you can't use polymorphism either if the class is allocated on the
stack, so TP-style objects and C++-classes behave the same here.

Regards,
Sven

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


Re: [fpc-pascal] Open array in object constructor gives error

2023-01-03 Thread Hairy Pixels via fpc-pascal


> On Jan 3, 2023, at 3:12 PM, Sven Barth  wrote:
> 
> But then you don't use the type name either. You simply do "o.Create(...)".
> 

O I get it now. I didn’t realize you couldn’t create on the type. That 
breaks my entire design then. It would be great to have a modern object that 
behaved more like classes but on the stack (like C++ does).

Regards,
Ryan Joseph

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


Re: [fpc-pascal] Open array in object constructor gives error

2023-01-03 Thread Sven Barth via fpc-pascal
Hairy Pixels  schrieb am Di., 3. Jan. 2023, 08:04:

>
>
> > On Jan 3, 2023, at 1:36 PM, Sven Barth 
> wrote:
> >
> > Objects are not classes, they don't know the Object Pascal style syntax
> for creating them, instead you need to use the syntax for objects from TP
> times:
>
> But why do you need to use New if you just want a stack allocated object?
> The constructor is called without New I thought?
>

But then you don't use the type name either. You simply do "o.Create(...)".

Regards,
Sven

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