Solved

about IniFile.WriteBinaryStream?

Posted on 2003-11-01
2
942 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now