MemoryStream ve iniFiles

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
lazymule
Üye
Mesajlar: 127
Kayıt: 16 Eki 2006 04:03
İletişim:

MemoryStream ve iniFiles

Mesaj gönderen lazymule »

merhabalar
Aşağıdaki koddaki sorun nedir sizce ? kaydettiğimi neden geri okuyamıyorum ? (stream 2 kb civarını geçince sorun ortaya çıkıyor)

Kod: Tümünü seç

procedure TForm1.Button1Click(Sender: TObject);
var iniF: TIniFile;
  Mem: TMemoryStream;
begin
//iniye kaydet
  iniF := TIniFile.Create('c:\Test.ini');
  Mem := TMemoryStream.Create;
  Mem.Clear;
  dxBarManager1.SaveToStream(Mem);
  Mem.Position := 0;
  iniF.WriteBinaryStream('Form1', 'Bars', Mem);
  iniF.Free;
  Mem.Free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var iniF: TIniFile;
  Mem: TMemoryStream;
begin
//iniden  oku
  iniF := TIniFile.Create('c:\Test.ini');
  Mem := TMemoryStream.Create;
  Mem.Clear;
  iniF.ReadBinaryStream('Form1', 'Bars', Mem);
  Mem.Position := 0;
  dxBarManager1.LoadFromStream(Mem);
  iniF.Free;
  Mem.Free;
end;
Evrende Ulaşılamayacak Tepe Yoktur !!!!
Yeterki İnsan Ulaşmak İstesin !!!!
http://www.maxiteknik.com
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

Hocam geri okurken 1023 karakter limitin varmış... Delphi help öyle diyor...
Delphi Help yazdı:ReadBinaryStream is limited to 1023 characters
Resim
Resim ....Resim
Kullanıcı avatarı
lazymule
Üye
Mesajlar: 127
Kayıt: 16 Eki 2006 04:03
İletişim:

Mesaj gönderen lazymule »

teşekkürler
sn. ARMAN hocam tüm ayarlarımı buna bezner bir sistemle kayıt ediyorum ini ile çok kolay olmuştu xml veya benzer bakınıyorum ama biraz zor olacak sanırım.
benzer kullanna bileceğim bir yöntem önerebilirmisin ? açık kodlu bir bileşende olabilir.
Evrende Ulaşılamayacak Tepe Yoktur !!!!
Yeterki İnsan Ulaşmak İstesin !!!!
http://www.maxiteknik.com
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

- Üçüncü parti bileşen deyince tüylerim diken diken oluyor, yapmayın zorda kalmadıkça kolayına kaçmayın...

- Alıştığın sistemi bırakmamak istersen INI'ye kaydederken bu limitleri gözeterek dilimlere ayırabilirsin. Okurken de bunları bir araya getirirsin ? olmaz mı ?

- Bak senin için bir kurgu hazırladım...
Kaydederken

Kod: Tümünü seç

Blok := 1023;
olan kısma dikkatini çekerim. bunu 1 arttırısan sonuç olumsuz olur ona göre :lol: 8)

// Kayıt Procedure

Kod: Tümünü seç

Procedure INISaveStream( Stream:TMemoryStream; DosyaAdi:TFileName; Section, Onisim : String );
var
  iniF  : TIniFile;
  i     : Integer;
  Mem   : TMemoryStream;
  Blok  : Integer;
begin
  iniF := TINIFile.Create( DosyaAdi );
  i := 0;
  // Öncelikle bu isimde dilimlenmiş veri varsa tümünü siliyoruz...
  // alan isim formatı aşağıda göreceğin üzere 'kısım', 'önisim0000000000' şeklinde...
  // Herhalde dilimler için 10 haneli bir rakam yeterli :)
  // Öncelikle bu isimde olan dilimleri siliyoruz.
  While iniF.ValueExists( Section, Format('%s%.10d', [OnIsim, i]) )
  do begin
    iniF.DeleteKey( Section, Format('%s%.10d', [OnIsim, i]) );
    Inc(i);
  end;

  Mem  := TMemoryStream.Create;
  i    := 0;
  Blok := 1023;
  Stream.Position := 0;
  While (Stream.Position < Stream.Size) do begin
    Mem.Clear;
    If Stream.Size >= (Stream.Position+Blok)
      then Mem.CopyFrom( Stream, Blok )
      else Mem.CopyFrom( Stream, Stream.Size - Stream.Position );
    Mem.Position := 0;
    iniF.WriteBinaryStream( Section, Format('%s%.10d', [OnIsim, i]), Mem );
    Inc(i);
  end;
  Mem.Free;
  iniF.Free;
end;
// Yükleme Procedure

Kod: Tümünü seç

Procedure INILoadStream( Var Stream:TMemoryStream; DosyaAdi:TFileName; Section, Onisim : String );
var
  iniF  : TIniFile;
  i     : Integer;
begin
  iniF := TINIFile.Create( DosyaAdi );
  i := 0;
  Stream.Clear;
  While iniF.ValueExists( Section, Format('%s%.10d', [OnIsim, i]) )
  do begin
    iniF.ReadBinaryStream( Section, Format('%s%.10d', [OnIsim, i]), Stream );
    Stream.Position := Stream.Size;
    Inc(i);
  end;
  Stream.Position := 0;
  iniF.Free;
end;
Kullanımı ise şöyle oluyor...

// Kaydetmek için

Kod: Tümünü seç

procedure TForm1.Button1Click(Sender: TObject);
var
  Mem: TMemoryStream;
begin
  Mem := TMemoryStream.Create;
  Mem.Clear;
  Image1.Picture.Bitmap.SaveToStream(Mem);
  Mem.Position := 0;
  INISaveStream( Mem, 'C:\Deneme.INI', 'Resimler', 'ARMAN' );
  Mem.Free;
  ShowMessage('İşlem Tamam');
end;
// Yüklmek için

Kod: Tümünü seç

procedure TForm1.Button2Click(Sender: TObject);
var
  Mem: TMemoryStream;
begin
  Mem := TMemoryStream.Create;
  INILoadStream( Mem, 'C:\Deneme.INI', 'Resimler', 'ARMAN' );
  Image2.Picture.Bitmap.LoadFromStream(Mem);
  Mem.Free;
  ShowMessage('Yükleme Tamam');
end;
Resim
Resim ....Resim
Kullanıcı avatarı
lazymule
Üye
Mesajlar: 127
Kayıt: 16 Eki 2006 04:03
İletişim:

Mesaj gönderen lazymule »

sn. mrmarman hocam gerçekten süpersin.
bu dosya okuma yazma işlerine hiçmi hiçkafam basmıyor.

Sn hocam delphiyi sen yazmadın değilmi ? :D

Kendimce Küçük bir bileşen yazmaya çalışıyorum incelmek isteyenler için kodları. incelemek isteyenler olursa baya bir sadeleştirilecek yeri var.
kodlar bir kaç bileşenden alınmadır ben sadece kendime işeme yarayacak şekilde bir araya getirmeye çalışıyorum

Kod: Tümünü seç

unit LmFormPlus;

interface

uses
  Registry, Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls,
  Graphics, inifiles, dialogs;
type
  TDbType = (dtINI, dtXML);
  TLmFormPlusDb = class(TComponent)
  private
    FDbType: TDbType;
    FINIFileName: string;
    procedure SetDbType(const Value: TDbType);
    procedure SetINIFileName(const Value: string);
  protected

  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function ReadString(const Section, Ident, Default: string): string; virtual;
    procedure WriteString(const Section, Ident, Value: string); virtual;
    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 ReadBinaryStream(const Section, Ident: string; Value: TStream): Integer; virtual;
    function ReadDate(const Section, Ident: string; Default: TDateTime): TDateTime; virtual;
    function ReadDateTime(const Section, Ident: string; Default: TDateTime): TDateTime; virtual;
    function ReadFloat(const Section, Ident: string; Default: Double): Double; virtual;
    function ReadTime(const Section, Ident: string; Default: TDateTime): TDateTime; virtual;
    procedure WriteBinaryStream(const Section, Ident: string; Value: TStream); virtual;
    procedure WriteDate(const Section, Ident: string; Value: TDateTime); virtual;
    procedure WriteDateTime(const Section, Ident: string; Value: TDateTime); virtual;
    procedure WriteFloat(const Section, Ident: string; Value: Double); virtual;
    procedure WriteTime(const Section, Ident: string; Value: TDateTime); virtual;

  published

    property DbType: TDbType read FDbType write SetDbType;
    property INIFileName: string read FINIFileName write SetINIFileName;

  end;

type
  TLmFormPlus = class;
  TEnterAsTab = class(TPersistent)
  private
    FEnable: Boolean;
    FSkipCompNames: TStrings;
    procedure SetEnable(const Value: Boolean);
    procedure SetSkipCompNames(const Value: TStrings);
  public
    constructor Create;
    destructor Destroy; override;
    function IsSkip(Name: string): Boolean;
  published
    property Enable: Boolean read FEnable write SetEnable default true;
    property SkipCompNames: TStrings read FSkipCompNames write SetSkipCompNames;
  end;
  TFormPosition = class(TPersistent)
  private
    FSave: Boolean;
    FLoad: Boolean;
    FFormName: string;
    procedure SetLoad(const Value: Boolean);
    procedure SetSave(const Value: Boolean);
    procedure SetFormName(const Value: string);
  public
    FormPointer: Pointer;
    constructor Create;
    destructor Destroy; override;
    procedure SetFormPointer(FP: Pointer);

  published
    property Save: Boolean read FSave write SetSave;
    property Load: Boolean read FLoad write SetLoad;
    property FormName: string read FFormName write SetFormName;
  end;

  TLmFormPlus = class(TComponent)
  private
    FOldWindowProc: TWndMethod;
    FEnterAsTab: TEnterAsTab;
    FFunctionKeysButton: array[1..12] of TControl;
    FFormPosition: TFormPosition;
    FLmFormPlusDb: TLmFormPlusDb;
    procedure SendClick(index: Integer);
    procedure WindowProc(var Message: TMessage);
    procedure SetEnterAsTab(const Value: TEnterAsTab);
    function GetFunctionKeysButton(const Index: Integer): TControl;
    procedure SetFunctionKeysButton(const Index: Integer; const Value: TControl);
    procedure SetFormPosition(const Value: TFormPosition);
    procedure SetLmFormPlusDb(const Value: TLmFormPlusDb);
  protected
    procedure Loaded; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure FormSave;
    procedure FormLoad;
  published
    property EnterAsTab: TEnterAsTab read FEnterAsTab write SetEnterAsTab;
    property FormPosition: TFormPosition read FFormPosition write SetFormPosition;
    property F1Button: TControl index 1 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F2Button: TControl index 2 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F3Button: TControl index 3 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F4Button: TControl index 4 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F5Button: TControl index 5 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F6Button: TControl index 6 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F7Button: TControl index 7 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F8Button: TControl index 8 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F9Button: TControl index 9 read GetFunctionKeysButton write SetFunctionKeysButton;
    property F10Button: TControl index 10 read GetFunctionKeysButton write SetFunctionKeysButton;
    property Esc: TControl index 11 read GetFunctionKeysButton write SetFunctionKeysButton;
    property PageDown: TControl index 12 read GetFunctionKeysButton write SetFunctionKeysButton;
    property LmFormPlusDb: TLmFormPlusDb read FLmFormPlusDb write SetLmFormPlusDb;
  end;

procedure Register;
implementation

uses Math;

procedure Register;
begin
  RegisterComponents('Lazymule', [TLmFormPlus]);
  RegisterComponents('Lazymule', [TLmFormPlusDb]);
end;

{ TLmFormPlus }

constructor TLmFormPlus.Create(AOwner: TComponent);
begin
  inherited;
  //Enter As Tab
  FEnterAsTab := TEnterAsTab.Create;
  FFormPosition := TFormPosition.Create;
  FFormPosition.FFormName := TForm(Owner).Name;
  if not (csDesigning in ComponentState) and (Owner is TForm) then
  begin
    FFormPosition.SetFormPointer(@Owner);
    FOldWindowProc := TForm(AOwner).WindowProc;
    TForm(AOwner).WindowProc := WindowProc;
  end;
end;

destructor TLmFormPlus.Destroy;
begin
  if not (csDesigning in ComponentState) and (Owner is TForm) then
  begin
    TForm(Owner).WindowProc := FOldWindowProc;
    FOldWindowProc := nil;
  end;
  inherited;
end;

procedure TLmFormPlus.FormLoad;
begin
  if FFormPosition.FLoad and Assigned(FLmFormPlusDb) then
  begin
    with self do
    begin
      if FLmFormPlusDb.readString(FFormPosition.FFormName, 'WindowState', '') = 'wsNormal' then
        TForm(Owner).WindowState := wsNormal;
      if FLmFormPlusDb.readString(FFormPosition.FFormName, 'WindowState', '') = 'wsMinimized' then
        TForm(Owner).WindowState := wsMinimized;
      if FLmFormPlusDb.readString(FFormPosition.FFormName, 'WindowState', '') = 'wsMaximized' then
        TForm(Owner).WindowState := wsMaximized;
      TForm(Owner).top := FLmFormPlusDb.readInteger(FFormPosition.FFormName, 'Top',
        TForm(Owner).Top);
      TForm(Owner).left := FLmFormPlusDb.readInteger(FFormPosition.FFormName, 'Left',
        TForm(Owner).Left);
      TForm(Owner).width := FLmFormPlusDb.readInteger(FFormPosition.FFormName, 'Width',
        TForm(Owner).Width);
      TForm(Owner).Height := FLmFormPlusDb.readInteger(FFormPosition.FFormName, 'Height',
        TForm(Owner).Height);
    end;
  end;
end;

procedure TLmFormPlus.FormSave;

begin

  if FFormPosition.FSave and Assigned(FLmFormPlusDb) then
  begin
    case TForm(Owner).WindowState of
      wsNormal:
        begin
          FLmFormPlusDb.WriteString(FFormPosition.FFormName, 'WindowState', 'wsNormal');
          FLmFormPlusDb.WriteInteger(FFormPosition.FFormName, 'Top', TForm(Owner).Top);
          FLmFormPlusDb.WriteInteger(FFormPosition.FFormName, 'Left', TForm(Owner).Left);
          FLmFormPlusDb.WriteInteger(FFormPosition.FFormName, 'Width', TForm(Owner).Width);
          FLmFormPlusDb.WriteInteger(FFormPosition.FFormName, 'Height', TForm(Owner).Height);
        end;
      wsMinimized: FLmFormPlusDb.WriteString(FFormPosition.FFormName, 'WindowState',
          'wsMinimized');
      wsMaximized: FLmFormPlusDb.WriteString(FFormPosition.FFormName, 'WindowState',
          'wsMaximized');
    end;

  end;

end;

function TLmFormPlus.GetFunctionKeysButton(const Index: Integer): TControl;
begin
  Result := FFunctionKeysButton[Index];
end;

procedure TLmFormPlus.Loaded;
begin
  inherited;
  if not (csDesigning in ComponentState) and (Owner is TForm) then
  begin
    FormLoad;
  end;
end;

procedure TLmFormPlus.SendClick(index: Integer);
var
  Comp: TControl;

begin
  if (GetAsyncKeyState(VK_LSHIFT) < 0) or
    (GetAsyncKeyState(VK_RSHIFT) < 0) or
    (GetAsyncKeyState(VK_LCONTROL) < 0) or
    (GetAsyncKeyState(VK_RCONTROL) < 0) then
    Exit;

  if Assigned(FFunctionKeysButton[Index]) then begin
    Comp := FFunctionKeysButton[Index];
    if (Comp is TWinControl) then begin
      TWinControl(Comp).SetFocus;
      case index of
        1..11: SendMessage(TWinControl(Comp).Handle, BM_CLICK, 0, 0);
      end;
    end;

  end;

end;

procedure TLmFormPlus.SetEnterAsTab(const Value: TEnterAsTab);
begin
  FEnterAsTab := Value;
end;

procedure TLmFormPlus.SetFormPosition(const Value: TFormPosition);
begin
  FFormPosition := Value;
end;

procedure TLmFormPlus.SetFunctionKeysButton(const Index: Integer;
  const Value: TControl);
begin
  if (FFunctionKeysButton[Index] <> Value) then
  begin
    FFunctionKeysButton[Index] := Value;
  end;
end;

procedure TLmFormPlus.SetLmFormPlusDb(const Value: TLmFormPlusDb);
begin
  FLmFormPlusDb := Value;
end;

procedure TLmFormPlus.WindowProc(var Message: TMessage);
begin
  case Message.Msg of
    WM_CLOSE:
      begin
        FormSave;
      end;
    45102:
      begin
        case Message.WParam of
          VK_F1: SendClick(1);
          VK_F2: SendClick(2);
          VK_F3: SendClick(3);
          VK_F4: SendClick(4);
          VK_F5: SendClick(5);
          VK_F6: SendClick(6);
          VK_F7: SendClick(7);
          VK_F8: SendClick(8);
          VK_F9: SendClick(9);
          VK_F10: SendClick(10);
          VK_ESCAPE: SendClick(11);
          VK_NEXT: SendClick(12);
        end;
      end;
    CM_DIALOGKEY:
      begin
        case Message.WParam of
          VK_RETURN:
            begin
              if not EnterAsTab.IsSkip(TForm(Owner).ActiveControl.Name) then
              begin
                keybd_event(VK_Tab, MapVirtualKey(VK_Tab, 0), 0, 0);
                keybd_event(VK_Tab, MapVirtualKey(VK_Tab, 0), KEYEVENTF_KEYUP,
                  0);
              end;
            end;
        end;
      end;
  end;
  FOldWindowProc(Message);
end;

{ TEnterAsTab }

constructor TEnterAsTab.Create;
begin
  FSkipCompNames := TStringList.Create;
  FEnable := True;

end;

destructor TEnterAsTab.Destroy;
begin
  FSkipCompNames.Free;
  inherited;
end;

function TEnterAsTab.IsSkip(Name: string): Boolean;
var i: Integer;
begin
  Result := False;
  for i := 0 to FSkipCompNames.Count - 1 do
  begin
    if FSkipCompNames.Strings[i] = Name then Result := True;
  end;

end;

procedure TEnterAsTab.SetEnable(const Value: Boolean);
begin
  FEnable := Value;
end;

procedure TEnterAsTab.SetSkipCompNames(const Value: TStrings);
begin
  FSkipCompNames.Assign(Value);
end;

{ TFormPosition }

constructor TFormPosition.Create;
begin
  FSave := True;
  FLoad := True;
end;

destructor TFormPosition.Destroy;
begin

  inherited;
end;

procedure TFormPosition.SetFormName(const Value: string);
begin
  if Value = '' then raise Exception.Create('Form Adı boş olamaz');
  FFormName := Value;
end;

procedure TFormPosition.SetFormPointer(FP: Pointer);
begin
  FormPointer := FP;
end;

procedure TFormPosition.SetLoad(const Value: Boolean);
begin
  FLoad := Value;
end;

procedure TFormPosition.SetSave(const Value: Boolean);
begin
  FSave := Value;
end;

{ TLmFormPlusDb }

constructor TLmFormPlusDb.Create(AOwner: TComponent);
begin
  inherited;
  FDbType := dtini;
  FINIFileName := ExtractFileDir(Application.ExeName + 'forms.ini')
end;

destructor TLmFormPlusDb.Destroy;
begin

  inherited;
end;

function TLmFormPlusDb.ReadBinaryStream(const Section, Ident: string;
  Value: TStream): Integer;

  procedure INILoadStream(var Stream: TMemoryStream; DosyaAdi: TFileName; Section, Onisim: string);
  var
    iniF: TIniFile;
    i: Integer;
  begin
    iniF := TINIFile.Create(DosyaAdi);
    i := 0;
    Stream.Clear;
    while iniF.ValueExists(Section, Format('%s%.10d', [OnIsim, i]))
      do begin
      iniF.ReadBinaryStream(Section, Format('%s%.10d', [OnIsim, i]), Stream);
      Stream.Position := Stream.Size;
      Inc(i);
    end;
    Stream.Position := 0;
    iniF.Free;
  end;
var
  Mem: TMemoryStream;

begin
  Result := -1;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin

          begin
            Mem := TMemoryStream.Create;
            INILoadStream(Mem, FINIFileName, Section, Ident);
            Mem.Position := 0;
            Mem.SaveToStream(Value);
            Mem.Free;
          end;
        end;
      end;
  end;

end;

function TLmFormPlusDb.ReadBool(const Section, Ident: string;
  Default: Boolean): Boolean;
var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadBool(Section, Ident, Default);
        end;
      end;
  end;

end;

function TLmFormPlusDb.ReadDate(const Section, Ident: string;
  Default: TDateTime): TDateTime;
var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadTime(Section, Ident, Default);
        end;
      end;

  end;

end;

function TLmFormPlusDb.ReadDateTime(const Section, Ident: string;
  Default: TDateTime): TDateTime;
var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadTime(Section, Ident, Default);
        end;
      end;
  end;

end;

function TLmFormPlusDb.ReadFloat(const Section, Ident: string;
  Default: Double): Double;
var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadTime(Section, Ident, Default);
        end;
      end;
  end;
end;

function TLmFormPlusDb.ReadInteger(const Section, Ident: string;
  Default: Integer): Longint;
var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadInteger(Section, Ident, Default);
        end;
      end;
  end;
end;

function TLmFormPlusDb.ReadString(const Section, Ident,
  Default: string): string;

var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadString(Section, Ident, Default);
        end;
      end;
  end;
end;

function TLmFormPlusDb.ReadTime(const Section, Ident: string;
  Default: TDateTime): TDateTime;
var INI: TIniFile;
begin
  Result := Default;
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          Result := INI.ReadTime(Section, Ident, Default);
        end;
      end;
  end;
end;

procedure TLmFormPlusDb.SetDbType(const Value: TDbType);
begin
  FDbType := Value;
end;

procedure TLmFormPlusDb.SetINIFileName(const Value: string);
begin
  FINIFileName := Value;
end;

procedure TLmFormPlusDb.WriteBinaryStream(const Section, Ident: string;
  Value: TStream);

  procedure INISaveStream(Stream: TMemoryStream; DosyaAdi: TFileName; Section, Onisim: string);
  var
    iniF: TIniFile;
    i: Integer;
    Mem: TMemoryStream;
    Blok: Integer;
  begin
    iniF := TINIFile.Create(DosyaAdi);
    i := 0;
    // http://www.delphiturkiye.com/forum/viewtopic.php?t=21029
       // Öncelikle bu isimde dilimlenmiş veri varsa tümünü siliyoruz...
        // alan isim formatı aşağıda göreceğin üzere 'kısım', 'önisim0000000000' şeklinde...
        // Herhalde dilimler için 10 haneli bir rakam yeterli :)
        // Öncelikle bu isimde olan dilimleri siliyoruz.
    while iniF.ValueExists(Section, Format('%s%.10d', [OnIsim, i]))
      do begin
      iniF.DeleteKey(Section, Format('%s%.10d', [OnIsim, i]));
      Inc(i);
    end;

    Mem := TMemoryStream.Create;
    i := 0;
    Blok := 1023;
    Stream.Position := 0;
    while (Stream.Position < Stream.Size) do begin
      Mem.Clear;
      if Stream.Size >= (Stream.Position + Blok)
        then Mem.CopyFrom(Stream, Blok)
      else Mem.CopyFrom(Stream, Stream.Size - Stream.Position);
      Mem.Position := 0;
      iniF.WriteBinaryStream(Section, Format('%s%.10d', [OnIsim, i]), Mem);
      Inc(i);
    end;
    Mem.Free;
    iniF.Free;
  end;
var

  Mem: TMemoryStream;
begin

  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          Mem := TMemoryStream.Create;
          Mem.Clear;
          Mem.LoadFromStream(Value);
          Mem.Position := 0;
          INISaveStream(Mem, FINIFileName, Section, Ident);
          Mem.Free;
          ShowMessage('İşlem Tamam');

        end;
      end;
  end;
end;

procedure TLmFormPlusDb.WriteBool(const Section, Ident: string;
  Value: Boolean);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteBool(Section, Ident, Value);
        end;
      end;
  end;
end;

procedure TLmFormPlusDb.WriteDate(const Section, Ident: string;
  Value: TDateTime);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteDate(Section, Ident, Value);
        end;
      end;
  end;
end;

procedure TLmFormPlusDb.WriteDateTime(const Section, Ident: string;
  Value: TDateTime);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteDateTime(Section, Ident, Value);
        end;
      end;
  end;
end;

procedure TLmFormPlusDb.WriteFloat(const Section, Ident: string;
  Value: Double);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteFloat(Section, Ident, Value);
        end;
      end;
  end;
end;

procedure TLmFormPlusDb.WriteInteger(const Section, Ident: string;
  Value: Integer);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteInteger(Section, Ident, Value);
        end;
      end;
  end;

end;

procedure TLmFormPlusDb.WriteString(const Section, Ident, Value: string);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteString(Section, Ident, Value);
        end;
      end;
  end;

end;

procedure TLmFormPlusDb.WriteTime(const Section, Ident: string;
  Value: TDateTime);
var INI: TIniFile;
begin
  case FDbType of
    dtINI:
      begin
        if FINIFileName <> '' then
        begin
          INI := TIniFile.Create(FINIFileName);
          INI.WriteTime(Section, Ident, Value);
        end;
      end;
  end;
end;

end.

Evrende Ulaşılamayacak Tepe Yoktur !!!!
Yeterki İnsan Ulaşmak İstesin !!!!
http://www.maxiteknik.com
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

Merhaba...

- Konumuza ilişkin bu bileşene minik bir ekleme önereyim o zaman...

Kod: Tümünü seç

function TLmFormPlusDb.ReadBinaryStream(const Section, Ident: string; 
  Value: TStream): Integer; 
bloğuna bir bakarsan

Kod: Tümünü seç

            Mem := TMemoryStream.Create; 
            INILoadStream(Mem, FINIFileName, Section, Ident); 
            Mem.Position := 0; 
            Mem.SaveToStream(Value); 
            Mem.Free; 
demişsin.. ya burada Value isimli dönen stream verinin position bilgisini 0 yapmayı ihmal ettiğinden bu işlemin kullanıcı tarafından yapılması gerekmekte. Oraya bir de Value.Position := 0; bu işi tam anlamıyla yerine getirmiş oldun demektir.

- Tebrik ederim. Güzel çalışma.
Resim
Resim ....Resim
Kullanıcı avatarı
lazymule
Üye
Mesajlar: 127
Kayıt: 16 Eki 2006 04:03
İletişim:

Mesaj gönderen lazymule »

teşekkürler ederim
önerinizi hemen ekledim. yardımlarınız için tekrar teşekkürler.
Evrende Ulaşılamayacak Tepe Yoktur !!!!
Yeterki İnsan Ulaşmak İstesin !!!!
http://www.maxiteknik.com
name
Kıdemli Üye
Mesajlar: 243
Kayıt: 09 Ağu 2003 02:11
Konum: İstanbul

Mesaj gönderen name »

Merhaba

Cevap yazılmış ancak bende bir ekleme yapmak istiyorum. TMemoryStream'ın dosyaya yazma ve dosyadan okuma özelliği var zaten neden IniFile kullanma ihtiyacı duyuluyor. Ayarlar ayrı bi dosyayada yazılabilir.

Kod: Tümünü seç

mem.SaveToFile('c:\bars.dat');

mem.LoadFromFile('c:\bars.dat');
Kullanıcı avatarı
lazymule
Üye
Mesajlar: 127
Kayıt: 16 Eki 2006 04:03
İletişim:

Mesaj gönderen lazymule »

Merhaba @name amacım tüm ayarların tek dosyada kalması bir yönden haklısın ayrı olması birşey fark etmiyor
ama tek dosyada tutmak işime geliyor buradaki diğer bir amacımda alt yapıyı hazırlamak kullanıcıların veya programın çalışması için gereken ayarlarıda sunucuda tutmayı planlıyorum.

Kod: Tümünü seç

TDbType = (dtINI, dtXML);  // devam eder gider
diğer bir sorunda 20 tane cxgridiniz var 20 sinede ayrı dosya pekde hoş olmazdı sanırım ne kadar düzenli yazarsanız yazın bir süre sonra işler karışıyor.
basit bir uygulamada kullandığım diğer bir yöntem. incele istersen çokda hoş olduğuna inanıyorum. dataset gibi düşündüm.
-yeni rapor ekleme

Kod: Tümünü seç

procedure TFrmReport.DBReportBeforePost(DataSet: TDataSet);
begin
  if (DBReport.State = dsinsert) and DBReportREPORT.IsNull then
  begin
    if FileExists(MyLib.ProgramYol(tyDatabase) + 'Temp.fr3') then
      DBReportREPORT.LoadFromFile(MyLib.ProgramYol(tyDatabase) + 'Temp.fr3')
    else
    begin
      raise Exception.Create('Yeni Rapor Oluşturulamadı');
      Abort;
    end;
  end;
end;
-Rapor yükleme

Kod: Tümünü seç

procedure TFrmReport.RaporYukle;
var FilterText      : string;
begin
  if DBReport.State = dsBrowse then
  begin
    ReportStream.Clear;
    FrmMain.DBAdres.Filtered := False;
    case YazdirmaTur.EditValue of
      0: FilterText := '';
      1: FilterText := '1____';
      2: FilterText := '_1___';
      3: FilterText := '__1__';
      4: FilterText := '___1_';
      5: FilterText := '____1';
    end;
    if not (FilterText = '') then
    begin
      FrmMain.DBAdres.Filter := 'ZARF like ' + QuotedStr(FilterText);

      FrmMain.DBAdres.Filtered := True;
    end;
    DBReportREPORT.SaveToStream(ReportStream);
    ReportStream.Position := 0;
    FrReport.LoadFromStream(ReportStream);
    FrReport.FileName := DBReportADI.AsString;
  end;

end;
--Rapor Kaydı

Kod: Tümünü seç

function TFrmReport.FrDesignerSaveReport(Report: TfrxReport;
  SaveAs: Boolean): Boolean;
begin
  ReportStream.Clear;
  Report.SaveToStream(ReportStream);
  ReportStream.Position := 0;
  DBReport.Edit;
  DBReportREPORT.LoadFromStream(ReportStream);
  DBReport.Post;
end;
Evrende Ulaşılamayacak Tepe Yoktur !!!!
Yeterki İnsan Ulaşmak İstesin !!!!
http://www.maxiteknik.com
Cevapla