?
Solved

finding & copying data from tmemorystream

Posted on 2006-05-07
7
Medium Priority
?
215 Views
Last Modified: 2010-04-05
hi

i have 2 text files loaded into two TMemoryStream's and i need to copy some data from each stream to a string

this is txt no 1:
language=EN;
Flash Type=Intel 28F320C3 2Mx16 BotB;
CPU Clock=200;
sdram_init=0x010b;
sdram_config=0x0062;
sdram_ncdl=0xfe0008;
pa0b0=0x168b;
pa0b1=0xfabf;
pa0b2=0xfeaf;
Write Mac Address=00:16:B6:A4:0C:65;

get wl_gmode=-1;

totalram=14761984, freeram=1241088, bufferram=1859584;
uptime=881703;

Total IEs = 0
eou_configured=1;
get_eou_index=1;
get_sn_index=0;
get_sn=;

get_mac_index=2;
get_mac=00:16:B6:A4:0C:65;
ses_status=short_push;
ses_count=1;

and this is txt no2:
Vendor:LINKSYS
ModelName:WRT54GS
Firmware Version:v4.70.8, Hyperwrt 2.1b1 + Thibor14 , Feb 23 2006
#:000
Boot Version:v3.7.4
CodePattern:W54S
Country:Europe

RF Status:disabled
RF Firmware Version:v4.70.8, Hyperwrt 2.1b1 + Thibor14
RF Domain:ETSI (channel 1~14)
RF Channel:6
RF SSID:linksys_OW_21548

-----Dynamic Information
RF Mac Address:
LAN Mac Address:00:16:B6:A4:0C:65
WAN Mac Address:00:16:B6:A4:0C:66
Hardware Version:2.0
Device Serial No.:

from txt no1 i need the value assigned to uptime
and from txt no2 i need the firmware version (without following it date, in this eg it would be 'v4.70.8, Hyperwrt 2.1b1 + Thibor14')
the data in those streams may be in different positions each time the procedure starts, so i need sthing that will search for it.

please help

sorry if the points for this Q are not sufficient, but thats all i've got left
oh... and sorry for my english

TY in advance
0
Comment
Question by:szafran
  • 4
  • 3
7 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 400 total points
ID: 16626714
easiest way would be to just read up all data into a string and do a pos and copy operation :)
but I'll put up a procedure that will search in the stream.

function extract(m:TStream; s:string):string;
// assumes delimiter is ; and value is after =
var t:string; c:integer; ch:char;
begin
  result:='';
  c:=length(s);
  setlength(t,c);
  repeat
    if m.Read(pansichar(t)^,c)<>c then exit;
    m.Seek(-c+1,soFromCurrent);
  until t=s;
  m.seek(c-1,soFromCurrent);
  t:='';
  if (m.read(ch,1) <>1) or (ch<>'=') then exit;
  repeat
    if m.read(ch,1) <>1 then exit;// delimiter not found
    if ch<>';' then t:=t+ch;
  until ch=';';
  result:=t;
end;

procedure TForm1.FormCreate(Sender: TObject);
var f:TMemoryStream; s:string;
begin
  s:=
'language=EN;'#13#10+
'Flash Type=Intel 28F320C3 2Mx16 BotB;'#13#10+
'CPU Clock=200;'#13#10+
'sdram_init=0x010b;'#13#10+
'sdram_config=0x0062;'#13#10+
'sdram_ncdl=0xfe0008;'#13#10+
'pa0b0=0x168b;'#13#10+
'pa0b1=0xfabf;'#13#10+
'pa0b2=0xfeaf;'#13#10+
'Write Mac Address=00:16:B6:A4:0C:65;'#13#10+
''#13#10+
'get wl_gmode=-1;'#13#10+
''#13#10+
'totalram=14761984, freeram=1241088, bufferram=1859584;'#13#10+
'uptime=881703;'#13#10+
''#13#10+
'Total IEs = 0'#13#10+
'eou_configured=1;'#13#10+
'get_eou_index=1;'#13#10+
'get_sn_index=0;'#13#10+
'get_sn=;'#13#10+
''#13#10+
'get_mac_index=2;'#13#10+
'get_mac=00:16:B6:A4:0C:65;'#13#10+
'ses_status=short_push;'#13#10+
'ses_count=1;';
  f:=TMemoryStream.Create;
  f.Write(pansichar(s)^,length(s));
  f.Seek(0,soFromBeginning);
  s:=extract(f,'uptime');
  showmessage(s);
  f.free;
end;

the easy way is to read upu in a string (you need to know the stream size) and then do a plain pos and copy. but the above works ok.

cheers
0
 

Author Comment

by:szafran
ID: 16630232
and how can i copy the stream into a string ?? i've tried doing it without positive results :/
0
 
LVL 28

Expert Comment

by:2266180
ID: 16630336
the way I wrote it, is the way you read it :)

  f:=TMemoryStream.Create;
  f.Write(pansichar(s)^,length(s));
  f.Seek(0,soFromBeginning);

  // you must know how big count is (for example, in this particular case: f.size)
  setlength(s,count); // make room for enough characters
  f.read(pansichar(s)^,count);// read them

didn't compile, not test, but should work. if it doesn't let me know, and I'll investigate in about an hour when I'll be able to access a delphi IDE.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:2266180
ID: 16630346
don't mind me asking, but why isn't the solution above satisfying? I mean it does the job as asked, no?
0
 

Author Comment

by:szafran
ID: 16630403
works
now i can write it with pos/copy =o]
thx very much for your help
0
 

Author Comment

by:szafran
ID: 16630416
if the code is simpler than it's better
and it'll be simpler with pos/copy
0
 
LVL 28

Expert Comment

by:2266180
ID: 16630539
makes sense :)
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question