Solved

Delphi Programming question

Posted on 1997-06-20
5
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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