Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2002.05.20;
Скачать: [xml.tar.bz2];

Вниз

Проблема при использовании TIniFile   Найти похожие ветки 

 
allrussia   (2002-05-07 08:06) [0]

Утро доброе.

Вот код:
procedure...
var
ini: TiniFile;
s: string;
begin
ini:=TIniFile.Create("c:\default.ini");
s:=ini.ReadString("Section","Value","");
ini.free;
end;

Запускаю программу, получаю значение s, выхожу из программы, изменяю значение s в default.ini, запускаю программу - s не изменилось. Приходится программу 2-2 раза запускать, чтобы s ихменилось. Что за...? Кто-нибудь знает?

Пробовал ini.destroy в Form.OnDestroy не помогает
Delphi3


 
gek   (2002-05-07 08:54) [1]

Очень странно.
Я с таким честно говоря не сталкивался.
Может перейти на версию выше?
Единственное, как читаешь ini; приведи код.


 
Alx2   (2002-05-07 08:58) [2]

Просто они кэшируются. Надо сбрасывать кэш.


 
Song   (2002-05-07 08:59) [3]

2gek © (07.05.02 08:54)
Приведёный пример - это и есть чтение.

2allrussia © (07.05.02 08:06)
У Вас запись на диск кэшируется, и данные записаться не успевают перед тем как Вы их повторно читаете. Вижу только такое объснение.


 
gek   (2002-05-07 09:01) [4]

> Song © (07.05.02 08:59)

Да, правильно.
Извени, недосмотрел.


 
Alx2   (2002-05-07 09:02) [5]

Вот, в догонку:
TIniFile.UpdateFile

Flushes buffered INI file data to disk.

function UpdateFile; override;

Description

Call UpdateFile to flush buffered reads from and writes to the INI file to disk. UpdateFile is useful under Windows95, but has no effect under Windows NT as NT does not buffer INI file reads and writes.


 
allrussia   (2002-05-07 10:26) [6]

Alx2>>>

Нет такой функции


 
Alx2   (2002-05-07 10:32) [7]

UpdateFile - метод в TIniFile. см. в Delphi Help компонент TIniFile и его методы.


 
allrussia   (2002-05-07 11:03) [8]

Да НЕТ такого метода:

TIniFile methods

TIniFile Alphabetically

In TIniFile

Create
DeleteKey
EraseSection
ReadBool
ReadInteger
ReadSection
ReadSections
ReadSectionValues
ReadString
WriteBool
WriteInteger
WriteString

Derived from TObject

ClassInfo
ClassName
ClassNameIs
ClassParent
ClassType
CleanupInstance
DefaultHandler
Destroy
Dispatch
FieldAddress
Free
FreeInstance
InheritsFrom
InitInstance
InstanceSize
MethodAddress
MethodName

NewInstance


 
Alx2   (2002-05-07 11:12) [9]


{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ }
{ Copyright (c) 1995,99 Inprise Corporation }
{ }
{*******************************************************}

unit IniFiles;

{$R-,T-,H+,X+}

interface

uses Windows, SysUtils, Classes;

type
TCustomIniFile = class(TObject)
private
FFileName: string;
public
constructor Create(const FileName: string);
function SectionExists(const Section: string): Boolean;
function ReadString(const Section, Ident, Default: string): string; virtual; abstract;
procedure WriteString(const Section, Ident, Value: String); virtual; abstract;
function ReadInteger(const Section, Ident: string; Default: Longint): Longint; virtual;
procedure WriteInteger(const Section, Ident: string; Value: Longint); virtual;
function ReadBool(const Section, Ident: string; Default: Boolean): Boolean; virtual;
procedure WriteBool(const Section, Ident: string; Value: Boolean); virtual;
function ReadDate(const Section, Name: string; Default: TDateTime): TDateTime; virtual;
function ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime; virtual;
function ReadFloat(const Section, Name: string; Default: Double): Double; virtual;
function ReadTime(const Section, Name: string; Default: TDateTime): TDateTime; virtual;
procedure WriteDate(const Section, Name: string; Value: TDateTime); virtual;
procedure WriteDateTime(const Section, Name: string; Value: TDateTime); virtual;
procedure WriteFloat(const Section, Name: string; Value: Double); virtual;
procedure WriteTime(const Section, Name: string; Value: TDateTime); virtual;
procedure ReadSection(const Section: string; Strings: TStrings); virtual; abstract;
procedure ReadSections(Strings: TStrings); virtual; abstract;
procedure ReadSectionValues(const Section: string; Strings: TStrings); virtual; abstract;
procedure EraseSection(const Section: string); virtual; abstract;
procedure DeleteKey(const Section, Ident: String); virtual; abstract;
procedure UpdateFile; virtual; abstract;
function ValueExists(const Section, Ident: string): Boolean;
property FileName: string read FFileName;
end;

{ TIniFile - Encapsulates the Windows INI file interface
(Get/SetPrivateProfileXXX functions) }

TIniFile = class(TCustomIniFile)
public
function ReadString(const Section, Ident, Default: string): string; override;
procedure WriteString(const Section, Ident, Value: String); override;
procedure ReadSection(const Section: string; Strings: TStrings); override;
procedure ReadSections(Strings: TStrings); override;
procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
procedure EraseSection(const Section: string); override;
procedure DeleteKey(const Section, Ident: String); override;
procedure UpdateFile; override;
end;

{ TMemIniFile - loads and entire ini file into memory and allows all
operations to be performed on the memory image. The image can then
be written out to the disk file }

TMemIniFile = class(TCustomIniFile)
private
FSections: TStringList;
function AddSection(const Section: string): TStrings;
procedure LoadValues;
public
constructor Create(const FileName: string);
destructor Destroy; override;
procedure Clear;
procedure DeleteKey(const Section, Ident: String); override;
procedure EraseSection(const Section: string); override;
procedure GetStrings(List: TStrings);
procedure ReadSection(const Section: string; Strings: TStrings); override;
procedure ReadSections(Strings: TStrings); override;
procedure ReadSectionValues(const Section: string; Strings: TStrings); override;
function ReadString(const Section, Ident, Default: string): string; override;
procedure Rename(const FileName: string; Reload: Boolean);
procedure SetStrings(List: TStrings);
procedure UpdateFile; override;
procedure WriteString(const Section, Ident, Value: String); override;
end;




 
Dinara   (2002-05-07 11:17) [10]

Может Delphi 3 виноват? В 6 есть.


 
Alx2   (2002-05-07 11:20) [11]

Действительно, D3 виноват :( не посмотрел....

Вот ее код:

procedure TMemIniFile.UpdateFile;
var
List: TStringList;
begin
List := TStringList.Create;
try
GetStrings(List);
List.SaveToFile(FFileName);
finally
List.Free;
end;
end;


 
Song   (2002-05-07 11:22) [12]

Интересно и что ж здесь такого, что выполняет ф-ию Flush ???


 
Alx2   (2002-05-07 11:23) [13]

Ой, сорри!
Вот код:

procedure TIniFile.UpdateFile;
begin
WritePrivateProfileString(nil, nil, nil, PChar(FFileName));
end;



 
allrussia   (2002-05-07 11:25) [14]

спасибо, счас буду пробывать


 
allrussia   (2002-05-07 11:40) [15]

Все работает, я просто юниты заменил и вызываю upDateFile перед ini.free



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2002.05.20;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.028 c
7-64848
777
2002-02-21 13:46
2002.05.20
Как узнать параметры процедуры из DLL?


7-64850
Sir Alex
2002-02-22 19:14
2002.05.20
Как отключить HDD от компа, на ХОДУ!


3-64515
Дремучий
2002-04-19 19:19
2002.05.20
Как получить список открытых сесий и ....?


3-64451
Mikeee
2002-04-21 11:02
2002.05.20
Как вставить дату в таблицу?


3-64519
Alex Spirin
2002-04-22 19:38
2002.05.20
Delphi + Excel = ?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский