smart-mobile-studio

Load a memo control from external file using Smart Mobile Studio 1.1


Ho do I load a memo control from external file

example: \res\info.txt

thanks


Solution

  • It looks like the folks at SMS have come up with a quick and dirty solution until they can add a LoadFromUrl method in th TStringList

    http://smartmobilestudio.com/forums/topic/loading-memo-from-file-resinfo-txt/

    Their solution works by adding LoadFromURL method to the TStringList class via a helper object. The code below is copied from the Smart Mobile Studio forum and adjusted to work with Smart Mobile Studio 1.1. You can use it unitil TStringList.LoadFromUrl appears in the RTL.

    type
      TStringlistHelper = class helper for TStringList
        procedure LoadFromUrl(aUrl:String;Callback: TProcedureRef = nil);
      end;
    
    procedure TStringlistHelper.LoadFromUrl(aUrl:String;
                Callback:TProcedureRef);
    var
      mRequest: TW3HttpRequest;
    begin
      mRequest:=TW3HttpRequest.Create;
      mRequest.OnDataReady:=procedure (Sender:TW3HttpRequest)
      begin
        self.text:=Sender.ResponseText;
        if assigned(Callback) then Callback;
        w3_callback(sender.free,100);
      end;
      mRequest.Get(aUrl);
    end;
    

    Just add this code to some unit and then use this unit in your project.