Solved

about IniFile.WriteBinaryStream?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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