Jump to content

Qasim Shahzad

Members
  • Content Count

    14
  • Joined

  • Last visited

Posts posted by Qasim Shahzad


  1. 2 hours ago, David Heffernan said:

    It depends what native is important. FMX doesn't use native GUI widgets and toolkits. 

     

    But it's native in the sense that the compiler emits code that runs on the metal. 

     

    To me it feels like the former is an important limitation and the latter is just not relevant. 

    Respected @David Heffernan. Thanks for your explanation. You are right. I think this is one of the main reasons Delphi does not natively support Right-To-Left Languages on Android because it is not using native components.

    What is your view about FPC and its nativeness?


  2. Thanks @programmerdelphi2k


    Those are valid points, and I totally agree with you here.


    But then someone might say, why not learn Python or something else instead of Delphi? As you said, the market will dictate its rules. I believe there are productivity and life-cycle maintenance benefits to using Delphi. But how can we logically convey these benefits to others?
     

    For example, we can say that Delphi can target many processors. Moreover, we can port our Delphi code to Free Pascal Compiler, and it can target many processor architectures. Like:

    1. Intel x86 (16 and 32 bit)
    2. AMD64/x86-64
    3. PowerPC
    4. PowerPC64
    5. SPARC
    6. SPARC64
    7. ARM
    8. AArch64
    9. MIPS
    10. Motorola 68k
    11. AVR
    12. JVM

  3. I plan to create some introductory videos for my DelphiTube channel on this topic:

    Delphi for C-Sharpers

     

    The question is, why should a C-Sharper (C# user) learn Delphi? I am definitely biased toward Delphi, but is it really beneficial for a C-Sharp user?

     

    My thoughts are:

    1. Learning another language is a good option.
    2. Delphi can create standalone executable that do not need third-party frameworks.
    3. You can build cross-platform native applications with Delphi.
    4. It would be an easy move if you joined through the C++ Builder path.
    5. Delphi is highly productive.


    What's your point of view? Can you add some reasons? Please guide.

    Thank you so much for your attention and participation.


  4. @dummzeuch

    Well, there are many wrong answers, but it will surely improve.

     

    The first time I used a pseudo-AI bot ELIZA, it was mind-blowing to my younger self at that time. Of course, Knight rider and many other sci-fi movies were also fascinating. 

     

    Now we reached a point where things are going in that direction. Still, we might be a decade or two away from a full-blown system, but things are racing now.


  5. It is strange how much ChatGPT "Knows" about Delphi and Pascal.

    Q. How to use ICS to fetch a webpage
    === === === === === === === === ===
    Ans:

    To use ICS (Internet Component Suite) to fetch a webpage in Delphi, you can follow these steps:

    Make sure that you have ICS installed on your system. If you are using the Embarcadero RAD Studio platform, ICS should already be included.

    In your Delphi project, add a reference to the ICS library by going to Project > Add to Project > Import a Type Library.

    In the Delphi unit where you want to fetch the webpage, add the following line at the top of the file to import the ICS components:

    uses Ics.HttpProt;

    Create an instance of the THttpCli component and set its URL property to the address of the webpage you want to fetch. For example:
    Copy code
    HttpCli.URL := 'https://www.example.com';
    Set the HttpCli.RcvdStream property to a TMemoryStream object, which will be used to store the data from the webpage.

    Call the HttpCli.GetAsync method to initiate the request to fetch the webpage. This method is asynchronous, which means that it will return immediately and the webpage data will be received in the background.

    To receive the data from the webpage, you will need to handle the HttpCli.DocData event. This event is triggered when data is received from the webpage. In the event handler, you can use the HttpCli.RcvdStream property to access the data that was received.

    When the request is complete, the HttpCli.DocBegin and HttpCli.DocEnd events will be triggered. You can use these events to clean up any resources that you have allocated and to notify the user that the request has completed.

    Here is an example of how you might use these steps to fetch a webpage and display its contents in a TMemo component:Copy code

    procedure TForm1.Button1Click(Sender: TObject);
    var
      HttpCli: THttpCli;
    begin
      HttpCli := THttpCli.Create(nil);
      try
        HttpCli.URL := 'https://www.example.com';
        HttpCli.RcvdStream := TMemoryStream.Create;
        HttpCli.OnDocData := HttpCliDocData;
        HttpCli.GetAsync;
      finally
        HttpCli.Free;
      end;
    end;
    
    procedure TForm1.HttpCliDocData(Sender: TObject; Buffer: Pointer;
      Len: Integer);
    begin
      Memo1.Lines.LoadFromStream(THttpCli(Sender).RcvdStream);
    end;


    This is just a basic example, and there are many other features and options available in ICS for more advanced scenarios. You can refer to the ICS documentation for more information.


  6. 9 hours ago, FredS said:

    Nearly all forms I show modal return a result.
    At the most basic level all these forms are inherited from one base form which has this code:

     

    
    class function TBaseDialogForm.ShowDialog(AOwner: TComponent): Boolean;
    begin
      with Create(AOwner) do
        try
          Result := ShowModal = mrOK;
        finally
          Free;
        end;
    end;
    
        class function ShowDialog(AOwner: TComponent): Boolean; virtual;

     

    That's good idea and we can get ModalResults with this method. Thanks for sharing.


  7. 39 minutes ago, Fr0sT.Brutal said:

    I have plenty of similar constructions in my DB app to edit some tables. So init is fully contained in form c-tor/design props/onShow, changes are applied internally and result is not important.

    Exactly, My usage is also like this. For any other scenario (In/Out Values) this might not be good solution. But for simple creation, display and destroy usage it is neat and time saving.


  8. 2 hours ago, Lajos Juhász said:

    When you're displaying the forms this way they are useless there are no input values to the form and the form doesn't produce any result. You're destroying the instance before the calling code could read the results back.

     

    I am aware that you can initialize the form in the formcreate and write the results back in formdestroy but that is a bad design.

    Yes these are valid concerns. But in my usage, these forms are like different parts of the application and mostly have no need to pass values or get result. Even if something is changed by a form like SettingsForm, It is persisted in file, DB or registry so next Form or Calling routine can/should load it from there. So in this scenario it is OK. But if it gets complex as you pointed out then we can create that form directly instead of calling a procedure.

    Nevertheless, your solution was a mental massage😊. This little problem/challenge was annoying me very much. Thank you so much. Stay Blessed.


  9. 9 hours ago, David Heffernan said:

    It will work fine so long as you use the virtual constructor and all your classes override that correctly. 

     

    If you passed in an anon method that creates and returns a newly minted form, that would allow other constructors to be used. 

     

    To me this is pointless though. It's a really common pattern, it's only a handful of lines. I don't really see the benefit.

     

    I mean, if you were trying to centralise some logging or other aspect, then it would make sense. Otherwise I don't really see the benefit. 

     

    Also the name sucks. Should include the fact that the form is shown modally. 

    That's great. These are valid concerns. To me the real benefit was readability and clean code. But centralizing logging is another benefit.

    Procedure name suggestion is also very thoughtful. It should be ShowModalForm Thank you so much.


  10. unit uMain;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Unit1,
      Unit2, Unit3;
    
    type
      TfrmMain = class ( TForm )
        BitBtn1: TBitBtn;
        BitBtn2: TBitBtn;
        BitBtn3: TBitBtn;
        procedure BitBtn1Click ( Sender: TObject ) ;
        procedure BitBtn2Click ( Sender: TObject ) ;
        procedure BitBtn3Click ( Sender: TObject ) ;
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      frmMain: TfrmMain;
    
    implementation
    
    {$R *.dfm}
    
    procedure ShowForm ( ThisForm: TFormClass ) ;
    var
      lForm: TForm;
    begin
      lForm := ThisForm.Create ( nil ) ;
      try
        lForm.ShowModal;
      finally
        lForm.Free;
      end;
    end;
    
    procedure TfrmMain.BitBtn1Click ( Sender: TObject ) ;
    begin
      ShowForm ( TForm1 ) ;
    end;
    
    procedure TfrmMain.BitBtn2Click ( Sender: TObject ) ;
    begin
      ShowForm ( TForm2 ) ;
    end;
    
    procedure TfrmMain.BitBtn3Click ( Sender: TObject ) ;
    begin
      ShowForm ( TForm3 ) ;
    end;
    
    end.
    
    

    Thank you so much. That was very clever. VCL version is working perfectly fine. I will check on FMX also.

     


    1. This call was successful in previous Delphi versions?
    2. Have you tried any other device?

    docwiki.embarcadero says:

    Quote

    On Android, it points to the device-specific location of the sandbox for the application;

    So it might be related to device or application permissions.


  11. Greetings Dear Delphians,

     

    Say we have 20 Forms in an App. We use these 6 lines to create 20 Forms at different places.

      Form1 := TForm1.Create;
      try
        Form1.ShowModal;
      finally
        Form1.Free;
      end;

     

    When refactoring we can see this is a lot of code duplication and we should encapsulate form creation in a procedure like this.
     

    procedure ShowForm ( ThisForm: TCustomForm ) ;
    begin
      ThisForm := TCustomForm(ThisFormClass.Create);//?? How to Get Form Class
      try
        ThisForm.ShowModal;
      finally
        ThisForm.Free;
      end;
    end;

    I only have problem in first line. how to get ThisForm parent class to call it.

    1. Is it even possible?
    2. If yes then how?
    3. What about FMX?

    Any help or pointer is appreciated.
    Thanks and stay blessed

×