Jump to content

om3raltiparmak

Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About om3raltiparmak

  • Birthday 10/01/1983

Technical Information

  • Delphi-Version
    Delphi 10.4 Sydney

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. SetLength(Data, x); I forgot. I added it and it worked.
  2. Hi all, I am trying to get the maximum value, minimum value and average in the values in a string and separated by ; but it gives an error. I am waiting for help. Example code ; Error : --------------------------- '1.5' is not a valid floating point value. --------------------------- Memo text : 1,5;2,1;1,6; 1,1;1,3;1; 1,9;0,1;0,5; var Data: array of Double; MinValue, MaxValue, Sum: Double; Average: Double; var i : integer; s : string; strArray : TArray<string>; charArray : Array[0..0] of Char; begin s := Memo1.Text; charArray[0] := ';'; strArray := s.Split(charArray); i := 0; for i := 0 to Length(strArray) do begin Data[i] := StrToFloat(strArray[i]); end; var Count: Integer; i: Integer; begin MinValue := Data[0]; MaxValue := Data[0]; Sum := 0; Count := Length(Data); for i := 0 to Count - 1 do begin if Data[i] < MinValue then MinValue := Data[i]; if Data[i] > MaxValue then MaxValue := Data[i]; Sum := Sum + Data[i]; end; Average := Sum / Count; Edit1.Text := FloatToStr(MinValue); Edit2.Text := FloatToStr(MaxValue); Edit3.Text := FloatToStr(Average); Edit4.Text := FloatToStr(Sum);
  3. Hi all, I tried to develop the HttpAsyncDownload sample application for myself in RAD Studio 10.4 Demos-master. The original application downloads the file from the URL contained in a single edit object. The filename is also being changed from another edit object. There is no error in the original application, it works smoothly. I wanted to encode the application for multi download and I added a listbox of random URLs in it. The application is running, but this time it thinks it has downloaded some files and gives the information that it is complete. It also downloads some files without any problems. Also, I added a code that will remove the edit object where the filename is written, to preserve the original filename in the URL. I am attaching the codes I edited below and the pas file of the original application. I will be glad if you can help me with the error. Example URL https://tdsoftware.files.wordpress.com/2010/10/delphi_giris.pdf https://dtffvb2501i0o.cloudfront.net/images/rad-studio/rad-11/RAD_11_Visuals_Set_5.png https://dtffvb2501i0o.cloudfront.net/images/rad-studio/rad-11/smartmockups_kt2ezvfb.png https://d3rs4yn018y0eg.cloudfront.net/tutorial/images/1470835852.jpg https://web.itu.edu.tr/~sakarya/files/delphi.pdf The Code I Edited By Myself System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Net.URLClient, System.Net.HttpClient, System.Net.HttpClientComponent, FMX.StdCtrls, FMX.Edit, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, System.ImageList, FMX.ImgList, FMX.Memo.Types, FMX.Layouts, FMX.ListBox; type TFormDownloadDemo = class(TForm) PanelTop: TPanel; PanelCenter: TPanel; LabelFile: TLabel; BStartDownload: TButton; Memo1: TMemo; ImageList1: TImageList; LabelURL: TLabel; LabelGlobalSpeed: TLabel; ProgressBarDownload: TProgressBar; BStopDownload: TButton; DPath: TEdit; ListBox1: TListBox; EditFileName: TEdit; Label1: TLabel; procedure BStartDownloadClick(Sender: TObject); procedure ButtonCancelClick(Sender: TObject); procedure BStartComponentClick(Sender: TObject); procedure ReceiveDataEvent(const Sender: TObject; AContentLength: Int64; AReadCount: Int64; var Abort: Boolean); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FClient: THTTPClient; FGlobalStart: Cardinal; FAsyncResult: IAsyncResult; FDownloadStream: TStream; procedure DoEndDownload(const AsyncResult: IAsyncResult); public { Public declarations } procedure SampleDownload; end; var FormDownloadDemo: TFormDownloadDemo; implementation {$R *.fmx} uses System.IOUtils; procedure TFormDownloadDemo.BStartDownloadClick(Sender: TObject); begin BStartDownload.Enabled := False; SampleDownload; end; procedure TFormDownloadDemo.ButtonCancelClick(Sender: TObject); begin (Sender as TButton).Enabled := False; FAsyncResult.Cancel; end; procedure TFormDownloadDemo.BStartComponentClick(Sender: TObject); begin BStartDownload.Enabled := False; SampleDownload; end; procedure TFormDownloadDemo.DoEndDownload(const AsyncResult: IAsyncResult); var LAsyncResponse: IHTTPResponse; begin try LAsyncResponse := THTTPClient.EndAsyncHTTP(AsyncResult); TThread.Synchronize(nil, procedure begin Memo1.Lines.Add('Download Finished!'); Memo1.Lines.Add(Format('Status: %d - %s', [LAsyncResponse.StatusCode, LAsyncResponse.StatusText])); end); finally LAsyncResponse := nil; FreeandNil(FDownloadStream); BStopDownload.Enabled := False; BStartDownload.Enabled := True; end; end; procedure TFormDownloadDemo.FormCreate(Sender: TObject); begin FClient := THTTPClient.Create; FClient.OnReceiveData := ReceiveDataEvent; end; procedure TFormDownloadDemo.FormDestroy(Sender: TObject); begin FDownloadStream.Free; FClient.Free; end; procedure TFormDownloadDemo.ReceiveDataEvent(const Sender: TObject; AContentLength, AReadCount: Int64; var Abort: Boolean); var LTime: Cardinal; LSpeed: Integer; begin LTime := TThread.GetTickCount - FGlobalStart; LSpeed := (AReadCount * 1000) div LTime; TThread.Queue(nil, procedure begin ProgressBarDownload.Value := AReadCount; LabelGlobalSpeed.Text := Format('Global speed: %d KB/s', [LSpeed div 1024]); end); end; procedure TFormDownloadDemo.SampleDownload; var URL: string; LResponse: IHTTPResponse; LFileName, Filename: string; LSize: Int64; i: integer; begin DPath.Text := TPath.GetDocumentsPath; i := 0; try for i := 0 to ListBox1.Items.Count-1 do begin ListBox1.ItemIndex := i; URL := ListBox1.Items[i]; Filename := StringReplace(URL, '/', '\', [rfReplaceAll]); LFileName := TPath.Combine(DPath.Text, ExtractFileName(Filename)); EditFilename.Text := ExtractFileName(Filename); LResponse := FClient.Head(URL); LSize := LResponse.ContentLength; Memo1.Lines.Add(Format('Head response: %d - %s', [LResponse.StatusCode, LResponse.StatusText])); LResponse := nil; ProgressBarDownload.Max := LSize; ProgressBarDownload.Min := 0; ProgressBarDownload.Value := 0; LabelGlobalSpeed.Text := 'Global speed: 0 KB/s'; Memo1.Lines.Add(Format('Downloading: "%s" (%d Bytes) into "%s"' , [ExtractFileName(Filename), LSize, LFileName])); // Create the file that is going to be dowloaded FDownloadStream := TFileStream.Create(LFileName, fmCreate); FDownloadStream.Position := 0; FGlobalStart := TThread.GetTickCount; // Start the download process FAsyncResult := FClient.BeginGet(DoEndDownload, URL, FDownloadStream); end; finally BStopDownload.Enabled := FAsyncResult <> nil; BStartDownload.Enabled := FAsyncResult = nil; end; end; end. FDownloadDemo.zip
×