Recent

Author Topic: Many Edit controls, One file output  (Read 1330 times)

Saylo_49

  • New Member
  • *
  • Posts: 43
Many Edit controls, One file output
« on: May 14, 2019, 08:20:47 pm »
Hello
I was working on a project that contain various text input controls (Combobox, Edit, Memo, Date picker) and the Open and Save features

Its task is to :
- load data in these controls from two separate file types
- save data from these controls to the two separate file types

The difference between the two file types is tags :
---------------------------------------------------------------------------------------------------------
- in type one (enw) it should save text like this :

Code: [Select]
%0 TYPE
%T TITLE
%A Author1
%A Author2
%A Author3
%D YEAR
%I PUBLISHER
%L LANGUAGE

where the (%*) representes the field tags and the CAPS (not case sensitive) representes the data strings in the controls
for %A  where Author1 is on line1 of the memo and Author2 on line2 and Author3 on line3
---------------------------------------------------------------------------------------------------------
- and in type two (bibtex) it should save text like this :

Code: [Select]
@xxxx{,
title={TITLE}, 
author={Author1 and Author2 and Author3},
year={YEAR}, 
publisher={PUBLISHER},
language={LANGUAGE}
}

where the (xxxx) represente the type choosen in a ComboBox
the CAPS (not case sensitive) representes the data strings in the controls
Author1 is on line1 of the memo and Author2 on line2 and Author3 on line3
---------------------------------------------------------------------------------------------------------

the problem is I tried everything I know but I couldn't make it work

Please help


---------------------------------------------
Lazarus : 2.0.2 - 32bit
FPC : 3.0.4
OS : Windows10 - 64bit
« Last Edit: May 14, 2019, 08:23:32 pm by Saylo_49 »
Lazarus 2.0.2 - FPC 3.0.4 - Win32

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Many Edit controls, One file output
« Reply #1 on: May 14, 2019, 10:39:17 pm »
the problem is I tried everything I know but I couldn't make it work

Well, that does not show in your example code.
It contains only 1 empty procedure.

Please put in a little more effort.

Also to me it is absolutely unclear what you want to achieve in the first place.

Bart

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Many Edit controls, One file output
« Reply #2 on: May 15, 2019, 01:20:16 am »
To write 2 files you should use TStringList.SaveToFile

Code: Pascal  [Select][+][-]
  1. with TStringList.Create do
  2. begin
  3.   Add(''); <-- here add line by line, as many as you need
  4.   SaveToFile('File1.txt');
  5.   Free;
  6. end

Saylo_49

  • New Member
  • *
  • Posts: 43
Re: Many Edit controls, One file output
« Reply #3 on: May 15, 2019, 02:50:23 am »
Please @Lainz
can you show me how to implement this snippet into this project
Lazarus 2.0.2 - FPC 3.0.4 - Win32

lainz

  • Hero Member
  • *****
  • Posts: 4468
    • https://lainz.github.io/
Re: Many Edit controls, One file output
« Reply #4 on: May 15, 2019, 03:26:00 am »
For example

Code: Pascal  [Select][+][-]
  1. Add('%0 TYPE');
  2. Add('%T TITLE');
  3. Add('%A ' + memo1.lines[0]);
  4. Add('%A '+ memo1.lines[1]);
  5. Add('%A '+ memo1.lines[2]);
  6. Add('%D YEAR');
  7. Add('%I PUBLISHER');
  8. Add('%L LANGUAGE');

Code: Pascal  [Select][+][-]
  1. Add('@' + combobox1.caption + '{,');
  2. Add('title={TITLE},');  
  3. Add('author={'+memo1.lines[0]+' and '+memo1.lines[1]+' and '+memo1.lines[2]+'},');
  4. Add('year={YEAR},');
  5. Add('publisher={PUBLISHER},');
  6. Add('language={LANGUAGE}');
  7. Add('}');

The same for the upper case names, just replace them concatenating strings.

But you as well need loading from these two file formats. That is a bit more complicated, I can't make it for you right now, but it involves reading line by line, then in the first type read until you found the character, for example the %A, so you know is an author, then read it into a memo as line 0. The same for the other types.

In the second file format, you can remove the commas, and then use TStringList to read key values, since these are already key values like author=value.

http://www.delphibasics.co.uk/RTL.asp?Name=tstringlist

There look at Example code : Using name-value strings
« Last Edit: May 15, 2019, 03:36:07 am by Lainz »

 

TinyPortal © 2005-2018