Solved

about IniFile.WriteBinaryStream?

Posted on 2003-11-01
2
971 Views
Last Modified: 2012-06-21
hi,experts
  why my code can not work!

function TResClass.AddToIni(IniFileName: string): boolean;
var
  IniFile: TIniFile;
  FileStream: TFileStream;
begin
  try
    try
      IniFile := TIniFile.Create(IniFileName);
      FileStream := TFileStream.Create(IniFileName, fmopenread or
        fmShareExclusive);
      IniFile.WriteBinaryStream('IniSction', IniFileName, FileStream);
    except
      result := false;
      exit;
    end;
  finally
    IniFile.Free;
    IniFile := nil;
  end;
  result := true;
end;

//
0
Comment
Question by:jbas
[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
2 Comments
 
LVL 5

Accepted Solution

by:
DeerBear earned 100 total points
ID: 9662563
Hi,

Because you're calling the same file and are opening the
file stream in exclusive mode.
But the file is already in use from the Ini class, so... you
can't have it!

HTH,

Andrew
0
 

Author Comment

by:jbas
ID: 9662633
DeerBear,thanks
i use this,it can work,      
FileStream := TFileStream.Create(IniFileName, fmopenread or
        fmShareDenyNone);

i call this
button.click:
AddToIni('d:\1.bmp');
when i first call this founction,this can only write "[IniSction]
kk",when i second call this founction,it can write some data,eg:
[IniSction]
kk=5B6D797365635D0D0A6B6B3D0D0A

but how i get the source,
function TResClass.GetResFile(IniFileName: string): boolean;
var
  IniFile: TIniFile;
  IniSction: string;
  FileMemStream: TMemoryStream;
begin
  try
    try
      IniFile := TIniFile.Create(IniFileName);
      FileMemStream := TMemoryStream.Create;
      IniFile.ReadBinaryStream('mysec', 'kk', FileMemStream);
      FileMemStream.SaveToFile('d:\gogo.bmp');
    except
      result := false;
      exit;
    end;
  finally
    IniFile.Free;
    IniFile := nil;
    FileMemStream.Free;
  end;
  result := true;
end;

it can not get the bmp,and the ini file limit 64k?

thanks!
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 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