what is the best way to parse a textfile or from Tmemo

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
mathsbertil
Newbie
Newbie
Posts: 14
Joined: Mon Feb 27, 2023 12:00 am

what is the best way to parse a textfile or from Tmemo

Post by mathsbertil » Mon May 29, 2023 12:57 pm

Hi!
What is the best way to parse fields (for example) 2,3,4,5 for showing a candle chart.

The lines are originally in a Tmemo

Thanks for helping!

mathsbertil
Newbie
Newbie
Posts: 14
Joined: Mon Feb 27, 2023 12:00 am

Re: what is the best way to parse a textfile or from Tmemo

Post by mathsbertil » Mon May 29, 2023 1:31 pm

1685311200, 4239,75, 4243,25, 4231,5, 4235,5, 4236,75, 6617, 2197
1685311500, 4235,75, 4237,5, 4232, 4233,25, 4234,6, 2521, 890
1685311800, 4233,25, 4234,5, 4231,5, 4232, 4233,3, 1517, 526
1685312100, 4232, 4233, 4230,25, 4232, 4231,5, 1568, 566
1685312400, 4232, 4235, 4231,5, 4233,5, 4233,525, 1154, 448
1685312700, 4233,75, 4234, 4232,25, 4233,5, 4233,1, 708, 294
1685313000, 4233,5, 4234,5, 4231,75, 4232, 4233,25, 808, 319

mathsbertil
Newbie
Newbie
Posts: 14
Joined: Mon Feb 27, 2023 12:00 am

Re: what is the best way to parse a textfile or from Tmemo

Post by mathsbertil » Mon May 29, 2023 2:08 pm

SeriesTextSource?

mathsbertil
Newbie
Newbie
Posts: 14
Joined: Mon Feb 27, 2023 12:00 am

Re: what is the best way to parse a textfile or from Tmemo

Post by mathsbertil » Mon May 29, 2023 3:59 pm

Import from memo.strings?

when using seriestext Tosource .. limitied to 2 fields"

When using TdbChart.. data is correct in text in Teechart but not in tdbchart.. see attached jpg

thanks ahead..
Attachments
chart uncomplete data.jpg
chart uncomplete data.jpg (54.88 KiB) Viewed 24511 times

mathsbertil
Newbie
Newbie
Posts: 14
Joined: Mon Feb 27, 2023 12:00 am

Re: what is the best way to parse a textfile or from Tmemo

Post by mathsbertil » Mon May 29, 2023 4:00 pm

I dont give input for name and data... only for pricefields

mathsbertil
Newbie
Newbie
Posts: 14
Joined: Mon Feb 27, 2023 12:00 am

Re: what is the best way to parse a textfile or from Tmemo

Post by mathsbertil » Mon May 29, 2023 4:14 pm

Index Close High Low Open
0 0 0 0 0
1 0 4232 0 0
2 4232 0 0 0
3 4232 0 4233 4232
4 0 0 4235 4232
5 0 0 4234 0
6 4232 0 0 0
7 0 0 0 4232
8 4231 0 0 0
9 0 0 4231 4231
10 0 4

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: what is the best way to parse a textfile or from Tmemo

Post by Yeray » Thu Jun 01, 2023 7:29 am

Hello,

A couple of considerations:
- Those strings use the same character (comma ,) both as DecimalSeparator and as FieldSeparator. You need to change one of them to be able to correctly identify values and fields.
I chose to modify the values from comma , to dot .:

Code: Select all

1685311200, 4239.75, 4243.25, 4231.5, 4235.5, 4236.75, 6617, 2197
1685311500, 4235.75, 4237.5, 4232, 4233.25, 4234.6, 2521, 890
1685311800, 4233.25, 4234.5, 4231.5, 4232, 4233.3, 1517, 526
1685312100, 4232, 4233, 4230.25, 4232, 4231.5, 1568, 566
1685312400, 4232, 4235, 4231.5, 4233.5, 4233.525, 1154, 448
1685312700, 4233.75, 4234, 4232.25, 4233.5, 4233.1, 708, 294
1685313000, 4233.5, 4234.5, 4231.75, 4232, 4233.25, 808, 319
- Those date values look strange. If I take one of them and I convert it to date I get 28605 as year:

Code: Select all

  ShowMessage(DateTimeToStr(StrToFloat('1685311200'))); // -> 04/05/28605
After correcting those issues, you should be able to do something like this:
Project3_2023-06-01_09-27-29.png
Project3_2023-06-01_09-27-29.png (16.34 KiB) Viewed 24422 times

Code: Select all

var Series1: TCandleSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart1.Color:=clWhite;
  Chart1.Gradient.Visible:=False;
  Chart1.Walls.Back.Color:=clWhite;
  Chart1.Walls.Back.Gradient.Visible:=False;

  Memo1.WordWrap:=False;
  
  FormatSettings.DecimalSeparator:='.';

  Series1:=TCandleSeries(Chart1.AddSeries(TCandleSeries));
  with Series1 do
  begin
    DownCloseColor:=1330417;
    UpCloseColor:=6519581;
  end;

  With SeriesTextSource1 do
  begin
    Series:=Series1;

    HeaderLines:=0;
    FieldSeparator:=',';
    Fields.Clear;
    AddField('Date',1).OnGetValue:=DateGetValue;
    AddField('High',2);
    AddField('Low',3);
    AddField('Open',4);
    AddField('Close',5);

    LoadFromStrings(Memo1.Lines);
  end;
end;

procedure TForm1.DateGetValue(Field:TSeriesTextField; const Text:string; var Value:Double);
begin
  //Value:=StrToFloat(Text);  // -> Correct Date from text
  Value:=IncDay(Today, Series1.Count);  // I'm using this as alternative to the above
  Series1.NotMandatoryValueList.TempValue:=Value;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply