Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi Programming question

Posted on 1997-06-20
5
Medium Priority
?
152 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

972 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