Jump to content

Ian Branch

Members
  • Content Count

    1272
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by Ian Branch


  1. Hi Uwe,

    D11.3, latest MMX.

    If I have this code in my type declaration:

    {code}

    ....

        procedure FormShow(Sender: TObject);
        procedure IndexOrdChange(Sender: TObject);
      private
        const iWidth = 920;
      end;

    implementation

    ''''

    {code}

     

    The function changes it to this:

    {code}

    ....

        procedure FormShow(Sender: TObject);
        procedure IndexOrdChange(Sender: TObject);
      private

      const                                       <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        const iWidth = 920;
      end;

    implementation

    ''''

    {code}

    Which of course causes an error.

     

    If I have this:

    {code}

    ....

        procedure FormShow(Sender: TObject);

    {$IFDEF MyTest}
        procedure IndexOrdChange(Sender: TObject);

    {$ENDIF}
      private
        const iWidth = 920;
      end;

    implementation

    ''''

    {code}

    It removes the $IFDEF/$ENDIF block totally.

     

    Regards,

    Ian


  2. CRACKED IT!!!!

    As Patrick suggested, put the Json request into the Custom body. 

    It didn't work for me the first time as I suspect I had the Json constructed wrong, and I still had Parameters in the RESTRequest.

    All sorted now.  Now to actually create the App.  🙂

    My thanks to all that contributed to my first foray into REST.  Appreciated.

     

    Regards,

    Ian

    • Like 1

  3. Hi Patrick,

    7 minutes ago, Patrick PREMARTIN said:

    Try to pass the parameters as BODY fields instead of GET/POST.

    You mean put this:

    "{"username": "email@mail.com", "secret":"password","shortcode":pacificbulksms","msisdn":"6798688008","message":"Hello James..."}"

    into the Custom body?  With the correct values of course. 😉

    I just tried that, same result.

     

    Ian


  4. Correction!  I thought it had been successful in the Debugger but I was looking in the wrong place. 😞

    Still an Empty Request error.

    This is the Debugger Request Tab:

    image.thumb.png.dae47282b13fab2525dee1bc900c8d0c.png

     

    This is the Parameters Tab, with key info changed: 😉

    image.thumb.png.2adc61d03cdcce49a7d94fb8221ce4ed.png

    You will note the 'Response' says 200:OK.....   But the Tabular Data Tab says it was an error.

    I spoke to the Phone owner and he hasn't received any messages.

    I'm confused.

     

    Ian

     

     

     


  5. Hi Patrick,

    When I put the Parameters into the REST Debugger, it says it is successful.

    When I have the parameters in the RESTRequest and right-click|Run, it is successful.

    But, If I leave The Client and Request exactly the same and inthe Delphi App do RESTRequest1.Execute, it fails. 😞

    procedure TForm12.btnComponentsClick(Sender: TObject);
    var
      obj, code, data: TJSONObject;
      sCode, url: string;
    begin
      //
      // Call the REST API and handle the response
      RESTRequest1.Execute;
      //
      ShowMessage('Status Code = ' + RESTResponse1.StatusCode.ToString);
      obj := RESTResponse1.JSONValue as TJSONObject;
      scode := obj.Values['code'].Value;
      data := obj.Values['data'] as TJSONObject;
      url := data.Values['text'].Value;
      ShowMessage('Code = ' + scode + sLineBreak + 'Text = ' + url);
    
    end;

    Returning 'Status Code = 200' for the first ShowMessage, and 'Code = 302  Text = Empty Request.....' for the second showmessage.  😞

     

    Regards,

    Ian


  6. Hi Team,

    I'm back.  Thank you for your inputs.

    I have this so far:

    procedure TForm12.Button1Click(Sender: TObject);
    begin
      //
    //  The RESTClient has already been configured.
    //
      RESTRequest1.AddParameter('username', 'email@email.com');      
      RESTRequest1.AddParameter('secret', 'password');
      RESTRequest1.AddParameter('shortcode', 'pacificbulksms');
      RESTRequest1.AddParameter('msisdn', '6799998122');               //  I take it this is the destination mobile Phone #??
      RESTRequest1.AddParameter('message', 'Hello World');
    
      // Call the REST API and handle the response
      RESTRequest1.Execute;
    
      // Access the response content
      if RESTResponse1.StatusCode = 200 then
      begin
        // Process the response content (e.g., RESTResponse.Content)
        var sResponse := RESTResponse1.Content;
        Label1.Caption := sResponse;
        //
        //  Example response  {"result":"success","code":"200","data":{"text":"SMS sent successfully."}}
        var sResult := GetResponseParameters(sResponse, 3, 4);
        var sCode := GetResponseParameters(sResponse, 7, 8);
        var sMessage := GetResponseParameters(sResponse, 13, 14);
      end
      else
      begin
        // Handle error cases
      end;
      //
    end;

    The RESTClient has the BaseURL set as "https://pacificbulksms.com".

    The RESTRequest has the Resource set as "api/restJson".

    Are there any other default settings I need to change, or settings I need to make?

    Aside of course getting actual usable test parameters from Vodaphone. 😉 

     

    Regards & TIA,

    Ian


  7. Hi Team,

    I am trying to assign the AfterEdit event to a TTable.

    I have this in the private area:

    procedure jtAfterEdit(Sender: TOBject);

    I have this in the DatamoduleCreate;

      JobTickets.AfterEdit := JTAfterEdit;

    And this as jtAfterEdit:

    procedure TdmC.JTAfterEdit(Sender: TOBject);
    begin
      //
        JobTickets.FieldByName('UserID').AsString := AUD.UserID;
        lNewRecord := False; //    Specifically reset the flag.
      //
    end;

    Delphi tells me that "[dcc32 Error] dmCurrent.pas(861): E2010 Incompatible types: 'TDataSet' and 'TObject'" for this line:

    JobTickets.AfterEdit := JTAfterEdit;

    What have I missed pls?

     

    Regards & TIA,

    Ian


  8. Hi Team,

    My Customer has asked me if I can add SMS sending to his Apps.

    In support he has sent me a document from Vodafone, he is a repairer for Vodafone, with the following information.

    image.thumb.png.8ee27feac03c35246c1e827e8198dcdf.png

    I know absolutely nothing about REST and/or its usage in/with Delphi.

    Could I prevail on someone to create a small delphi unit that incorporates whatever is necessary to send an sms?

    It would be very much appreciated.

    Regards & TIA,

    Ian

     

     


  9. Hi Team,

    In some places, not all, the use of a Credit Card to pay by a Customer incurs a 'Bank Fee' on the Seller.

    The Seller offsets this by adding an appropriate 'Bank Fee' to the sale.

    Question - Where VAT/GST applies, the Sale will incur a VAT/GST as part of the Sell Price.  Does the 'Bank Fee' also incur the VAT/GST?

    What is the general experience/knowledge?

     

    Regards & TIA,

    Ian


  10. Hi Team,

    I redid my routine to use StrCmpLogicalW.  Now I get...

    image.thumb.png.d92e9eabc810e6a011b392eefba6036a.png

    uses System.Generics.Defaults;
    
    procedure SortStringArray(var AStringArray: TArray<string>);
    var
      Comparer: IComparer<string>;
    begin
        Comparer := TComparer<string>.Construct(
          function(const ALeft, ARight: string): Integer
          begin
            Result := StrCmpLogicalW(PChar(ALeft.ToLower), PChar(ARight.ToLower));
          end
        );
    
      // Sort the string array using the custom comparer
      TArray.Sort<string>(AStringArray, Comparer);
    end;

     

    Regards & Tks.

     

    Ian

     


  11. Hi Team,

    I have been following this thread because I have a need.

    What would be the correct natural sort order for these?

    'file10.txt', 'File2.txt', '2fileb.txt', 'file1.txt', '1FileA.txt', 'file20.txt', '12fiLe.txt', 'file11.txt', '10file.txt'

    Is there a reference for dictating Natural Sort Order rules?

    I have my own StringArray Natural Sorting routines and they seem to work.  I just want to make sure they are giving me the correct result IAW NSO rules.

    This is what I am producing att:

    image.thumb.png.fdd83fb0d14bc55381b08573b411553d.png

     

    Regards & TIA,

    Ian


  12. Hi Team,

    D11.3.

    Is there a way to pickup the number at build/compile time so I can include it in a log message?

    e.g.  something like..LogMessage('This is line # '+%LineNumber%);

    I know I can hard code it but it would need to be re-done every time there is a code change.

    Regards & TIA,

    Ian 


  13. Hi Team,

    Despite my pitiful efforts I have managed to get App Tethering working between two Apps.

    But, I have a problem.  IIUC, the Sender has to be running before the Receiver.  Something about establishing a socket

    This I can't guarantee.  😞

    Is there any way to configure App Tethering so it dosn't matter if the Sender or Receiver starts first??

     

    Regards & TIA,

    Ian

×