Solved

Delphi Programming question

Posted on 1997-06-20
5
144 Views
Last Modified: 2010-04-04
What i want to do is to write a binary value (record called Settings) into the registry as a binary instead of to a file. It is 176 bytes in length and for the life of me i can't get the WriteBinaryData to work.  I know this will be something simple. Could someone please post me a small sample of code that i need and what parms to put where to get this procedure working. and how do you tell it what binary data to write to it.

Thanks.
Dane.

--- Cut From Delphi 2 Help File.

Applies to

TRegistry object, TRegIniFile object

Declaration

procedure WriteBinaryData(const Name: string; var Buffer; BufSize: Integer);
0
Comment
Question by:Dane Pickering
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1337350
Send the code and i'll have a look.

/// John
0
 
LVL 2

Author Comment

by:Dane Pickering
ID: 1337351
i have no code to give, thats what i need a small sample of code with the correct way ti write a record to a registry. i need to know the correct way to do this.

Regards,
Dane.
0
 
LVL 4

Accepted Solution

by:
erajoj earned 0 total points
ID: 1337352
Hi again!

This really simple code does, hopefully, what you want.

procedure TMainForm.Button15Click(Sender: TObject);
type
  TTestRec = record
    Name  : string[10];
    Number: Comp;
  end;
var
  Ini: TRegistry;
  Rec: TTestRec;
begin
  Ini := TRegistry.Create;
  if Ini.OpenKey('\software\Dane\Recs', True)
  then begin
    with Rec do begin
      Name := 'Dane';
      Number := 8630007314.0;
    end;
    Ini.WriteBinaryData('TestBuffer', Rec, SizeOf(TTestRec));

    FillChar(Rec, SizeOf(TTestRec), 0); // Clear record contents

    Ini.ReadBinaryData('TestBuffer', Rec, SizeOf(TTestRec));
    with Rec do begin
      Caption := Format('%s - %.0f', [Name, Number]);
    end;
  end;
  Ini.Free;
end;

Enjoy!

/// John
0
 
LVL 2

Author Comment

by:Dane Pickering
ID: 1337353
Ok, well that worked and that is exactly the same way that i was trying to get it to work. Umm, i couldn't see any difference, but al least it works. So you can have the points!

Thanks mate!

Regards,
Dane
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337354
Well, thanks alot for the nil-pointer... :-)

/// John

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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