[JEDI.NET-commits] main/examples/Jedi.IO/StreamOfValueType WinFormMain.pas,NONE,1.1 WinFormMain.resx
Status: Pre-Alpha
Brought to you by:
jedi_mbe
From: Marcel B. <jed...@us...> - 2005-03-14 14:19:08
|
Update of /cvsroot/jedidotnet/main/examples/Jedi.IO/StreamOfValueType In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27910/main/examples/Jedi.IO/StreamOfValueType Added Files: WinFormMain.pas WinFormMain.resx example.StreamOfValueType.bdsproj example.StreamOfValueType.dpr Log Message: * Moved example for FileOfRecord to new folder and renamed the example. --- NEW FILE: WinFormMain.pas --- {****************************************************************** JEDI.NET Demo Copyright (C) 2004 Project JEDI Original author: Andreas Hausladen You may retrieve the latest version of this file at the JEDI.NET home page, located at http://jedidotnet.sourceforge.net The contents of this file are used with permission, subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1_1Final.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. ******************************************************************} unit WinFormMain; interface uses System.Drawing, System.Collections, System.ComponentModel, System.Windows.Forms, System.Data, System.IO, Jedi.IO.FileOfRec; type TWinFormMain = class(System.Windows.Forms.Form) {$REGION 'Designer Managed Code'} strict private Components: System.ComponentModel.Container; Label1: System.Windows.Forms.Label; TextBoxName: System.Windows.Forms.TextBox; Label2: System.Windows.Forms.Label; NumericUpDownAge: System.Windows.Forms.NumericUpDown; Panel1: System.Windows.Forms.Panel; Label3: System.Windows.Forms.Label; NumericUpDownIncome: System.Windows.Forms.NumericUpDown; LabelRecords: System.Windows.Forms.Label; ListViewRecords: System.Windows.Forms.ListView; ButtonQuit: System.Windows.Forms.Button; ButtonAddRecord: System.Windows.Forms.Button; ButtonOverwrite: System.Windows.Forms.Button; procedure InitializeComponent; procedure ButtonQuit_Click(sender: System.Object; e: System.EventArgs); procedure ButtonAddRecord_Click(sender: System.Object; e: System.EventArgs); procedure TWinFormMain_Load(sender: System.Object; e: System.EventArgs); procedure ButtonOverwrite_Click(sender: System.Object; e: System.EventArgs); procedure ListViewRecords_SelectedIndexChanged(sender: System.Object; e: System.EventArgs); {$ENDREGION} strict protected procedure Dispose(Disposing: Boolean); override; private FFileName: string; procedure PopulateListViewRecords; public ColumnHeader1: System.Windows.Forms.ColumnHeader; constructor Create; end; [assembly: RuntimeRequiredAttribute(TypeOf(TWinFormMain))] TPersonRec = record Name: string[30]; Age: Byte; Income: Double; end; implementation {$AUTOBOX ON} {$REGION 'Windows Form Designer generated code'} procedure TWinFormMain.InitializeComponent; type TArrayOfInteger = array of Integer; TArrayOfSystem_Windows_Forms_ColumnHeader = array of System.Windows.Forms.ColumnHeader; begin Self.Panel1 := System.Windows.Forms.Panel.Create; Self.Label3 := System.Windows.Forms.Label.Create; Self.NumericUpDownIncome := System.Windows.Forms.NumericUpDown.Create; Self.NumericUpDownAge := System.Windows.Forms.NumericUpDown.Create; Self.Label2 := System.Windows.Forms.Label.Create; Self.TextBoxName := System.Windows.Forms.TextBox.Create; Self.Label1 := System.Windows.Forms.Label.Create; Self.LabelRecords := System.Windows.Forms.Label.Create; Self.ListViewRecords := System.Windows.Forms.ListView.Create; Self.ColumnHeader1 := System.Windows.Forms.ColumnHeader.Create; Self.ButtonQuit := System.Windows.Forms.Button.Create; Self.ButtonAddRecord := System.Windows.Forms.Button.Create; Self.ButtonOverwrite := System.Windows.Forms.Button.Create; Self.Panel1.SuspendLayout; (System.ComponentModel.ISupportInitialize(Self.NumericUpDownIncome)).BeginInit; (System.ComponentModel.ISupportInitialize(Self.NumericUpDownAge)).BeginInit; Self.SuspendLayout; // // Panel1 // Self.Panel1.Controls.Add(Self.Label3); Self.Panel1.Controls.Add(Self.NumericUpDownIncome); Self.Panel1.Controls.Add(Self.NumericUpDownAge); Self.Panel1.Controls.Add(Self.Label2); Self.Panel1.Controls.Add(Self.TextBoxName); Self.Panel1.Controls.Add(Self.Label1); Self.Panel1.Location := System.Drawing.Point.Create(8, 8); Self.Panel1.Name := 'Panel1'; Self.Panel1.Size := System.Drawing.Size.Create(224, 160); Self.Panel1.TabIndex := 7; // // Label3 // Self.Label3.Location := System.Drawing.Point.Create(16, 112); Self.Label3.Name := 'Label3'; Self.Label3.Size := System.Drawing.Size.Create(72, 16); Self.Label3.TabIndex := 13; Self.Label3.Text := 'Income:'; // // NumericUpDownIncome // Self.NumericUpDownIncome.DecimalPlaces := 2; Self.NumericUpDownIncome.Location := System.Drawing.Point.Create(16, 128); Self.NumericUpDownIncome.Maximum := System.Decimal.Create(TArrayOfInteger.Create(100000000, 0, 0, 0)); Self.NumericUpDownIncome.Name := 'NumericUpDownIncome'; Self.NumericUpDownIncome.TabIndex := 12; Self.NumericUpDownIncome.TextAlign := System.Windows.Forms.HorizontalAlignment.Right; // // NumericUpDownAge // Self.NumericUpDownAge.Location := System.Drawing.Point.Create(16, 80); Self.NumericUpDownAge.Maximum := System.Decimal.Create(TArrayOfInteger.Create(300, 0, 0, 0)); Self.NumericUpDownAge.Name := 'NumericUpDownAge'; Self.NumericUpDownAge.Size := System.Drawing.Size.Create(56, 20); Self.NumericUpDownAge.TabIndex := 11; Self.NumericUpDownAge.TextAlign := System.Windows.Forms.HorizontalAlignment.Right; Self.NumericUpDownAge.Value := System.Decimal.Create(TArrayOfInteger.Create(1, 0, 0, 0)); // // Label2 // Self.Label2.Location := System.Drawing.Point.Create(16, 64); Self.Label2.Name := 'Label2'; Self.Label2.Size := System.Drawing.Size.Create(24, 16); Self.Label2.TabIndex := 10; Self.Label2.Text := 'Age'; // // TextBoxName // Self.TextBoxName.Location := System.Drawing.Point.Create(16, 32); Self.TextBoxName.Name := 'TextBoxName'; Self.TextBoxName.Size := System.Drawing.Size.Create(152, 20); Self.TextBoxName.TabIndex := 9; Self.TextBoxName.Text := ''; // // Label1 // Self.Label1.Location := System.Drawing.Point.Create(16, 16); Self.Label1.Name := 'Label1'; Self.Label1.Size := System.Drawing.Size.Create(40, 16); Self.Label1.TabIndex := 8; Self.Label1.Text := 'Name:'; // // LabelRecords // Self.LabelRecords.Location := System.Drawing.Point.Create(384, 176); Self.LabelRecords.Name := 'LabelRecords'; Self.LabelRecords.Size := System.Drawing.Size.Create(136, 16); Self.LabelRecords.TabIndex := 8; Self.LabelRecords.Text := '{0} records'; Self.LabelRecords.TextAlign := System.Drawing.ContentAlignment.MiddleRight; // // ListViewRecords // Self.ListViewRecords.Columns.AddRange(TArrayOfSystem_Windows_Forms_ColumnHeader.Create(Self.ColumnHeader1)); Self.ListViewRecords.FullRowSelect := True; Self.ListViewRecords.HideSelection := False; Self.ListViewRecords.Location := System.Drawing.Point.Create(240, 8); Self.ListViewRecords.MultiSelect := False; Self.ListViewRecords.Name := 'ListViewRecords'; Self.ListViewRecords.Size := System.Drawing.Size.Create(280, 160); Self.ListViewRecords.TabIndex := 9; Self.ListViewRecords.View := System.Windows.Forms.View.Details; Include(Self.ListViewRecords.SelectedIndexChanged, Self.ListViewRecords_SelectedIndexChanged); // // ColumnHeader1 // Self.ColumnHeader1.Text := 'Name'; Self.ColumnHeader1.Width := 200; // // ButtonQuit // Self.ButtonQuit.Location := System.Drawing.Point.Create(448, 200); Self.ButtonQuit.Name := 'ButtonQuit'; Self.ButtonQuit.TabIndex := 10; Self.ButtonQuit.Text := '&Quit'; Include(Self.ButtonQuit.Click, Self.ButtonQuit_Click); // // ButtonAddRecord // Self.ButtonAddRecord.Location := System.Drawing.Point.Create(8, 200); Self.ButtonAddRecord.Name := 'ButtonAddRecord'; Self.ButtonAddRecord.TabIndex := 11; Self.ButtonAddRecord.Text := 'Add Record'; Include(Self.ButtonAddRecord.Click, Self.ButtonAddRecord_Click); // // ButtonOverwrite // Self.ButtonOverwrite.Location := System.Drawing.Point.Create(96, 200); Self.ButtonOverwrite.Name := 'ButtonOverwrite'; Self.ButtonOverwrite.TabIndex := 12; Self.ButtonOverwrite.Text := '&Replace'; Include(Self.ButtonOverwrite.Click, Self.ButtonOverwrite_Click); // // TWinFormMain // Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13); Self.ClientSize := System.Drawing.Size.Create(544, 230); Self.Controls.Add(Self.ButtonOverwrite); Self.Controls.Add(Self.ButtonAddRecord); Self.Controls.Add(Self.ButtonQuit); Self.Controls.Add(Self.ListViewRecords); Self.Controls.Add(Self.LabelRecords); Self.Controls.Add(Self.Panel1); Self.Name := 'TWinFormMain'; Self.StartPosition := System.Windows.Forms.FormStartPosition.CenterScreen; Self.Text := 'Jedi.System.IO.FileOfRecord Test'; Include(Self.Load, Self.TWinFormMain_Load); Self.Panel1.ResumeLayout(False); (System.ComponentModel.ISupportInitialize(Self.NumericUpDownIncome)).EndInit; (System.ComponentModel.ISupportInitialize(Self.NumericUpDownAge)).EndInit; Self.ResumeLayout(False); end; {$ENDREGION} procedure TWinFormMain.Dispose(Disposing: Boolean); begin if Disposing then begin if Components <> nil then Components.Dispose(); end; inherited Dispose(Disposing); end; constructor TWinFormMain.Create; begin inherited Create; InitializeComponent; FFileName := Directory.GetCurrentDirectory + '/ExampleFileOfValueType.rnd'; end; procedure TWinFormMain.ListViewRecords_SelectedIndexChanged(sender: System.Object; e: System.EventArgs); var f: FileOfRecord; r: TPersonRec; begin ButtonOverwrite.Enabled := False; if ListViewRecords.SelectedItems.Count > 0 then begin // C# users are required to use the FileOfValueType class; FileOfRecord is // just a convienient alias to FileOfValueType and only available to Delphi // users f := FileOfRecord.Create( TypeOf(TPersonRec), FFileName ); try // seek to the selected item f.Seek(Integer(ListViewRecords.SelectedItems[0].Tag)); f.Read(r); TextBoxName.Text := r.Name; NumericUpDownAge.Value := r.Age; NumericUpDownIncome.Value := r.Income; ButtonOverwrite.Enabled := True; finally f.Free; end; end else begin TextBoxName.Text := ''; NumericUpDownAge.Value := 0; NumericUpDownIncome.Value := 0; end; end; procedure TWinFormMain.ButtonOverwrite_Click(sender: System.Object; e: System.EventArgs); var f: FileOfRecord; r: TPersonRec; begin // C# users are required to use the FileOfValueType class; FileOfRecord is // just a convienient alias to FileOfValueType and only available to Delphi // users f := FileOfRecord.Create( TypeOf(TPersonRec), FFileName ); try // seek to the selected item f.Seek(Integer(ListViewRecords.SelectedItems[0].Tag)); r.Name := TextBoxName.Text; r.Age := Decimal.ToByte(NumericUpDownAge.Value); r.Income := Decimal.ToDouble(NumericUpDownIncome.Value); f.Write(r); finally f.Free; end; PopulateListViewRecords; TextBoxName.Text := ''; NumericUpDownAge.Value := 0; NumericUpDownIncome.Value := 0; Control(TextBoxName).Focus; end; procedure TWinFormMain.TWinFormMain_Load(sender: System.Object; e: System.EventArgs); begin PopulateListViewRecords; end; procedure TWinFormMain.PopulateListViewRecords; var f: FileOfRecord; r: TPersonRec; begin ButtonOverwrite.Enabled := False; ListViewRecords.Items.Clear; if &File.Exists(FFileName) then begin // C# users are required to use the FileOfValueType class; FileOfRecord is // just a convienient alias to FileOfValueType and only available to Delphi // users f := FileOfRecord.Create( TypeOf(TPersonRec), FFileName ); try while not f.Eof do begin f.Read(r); ListViewRecords.Items.Add(r.Name).Tag := Integer(f.Position - 1); end; finally f.Free; end; end; LabelRecords.Text := System.String.Format('{0} records', ListViewRecords.Items.Count); end; procedure TWinFormMain.ButtonAddRecord_Click(sender: System.Object; e: System.EventArgs); var f: FileOfRecord; r: TPersonRec; begin // C# users are required to use the FileOfValueType class; FileOfRecord is // just a convienient alias to FileOfValueType and only available to Delphi // users f := FileOfRecord.Create( TypeOf(TPersonRec), FFileName ); try f.Seek(f.RecordCount); r.Name := TextBoxName.Text; r.Age := Decimal.ToByte(NumericUpDownAge.Value); r.Income := Decimal.ToDouble(NumericUpDownIncome.Value); f.Write(r); finally f.Free; end; PopulateListViewRecords; TextBoxName.Text := ''; NumericUpDownAge.Value := 0; NumericUpDownIncome.Value := 0; Control(TextBoxName).Focus; end; procedure TWinFormMain.ButtonQuit_Click(sender: System.Object; e: System.EventArgs); begin Close; end; end. --- NEW FILE: example.StreamOfValueType.dpr --- program example.StreamOfValueType; {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Data.dll'} {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Drawing.dll'} {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Windows.Forms.dll'} {%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.XML.dll'} {$R 'WinFormMain.TWinFormMain.resources' 'WinFormMain.resx'} {%DelphiDotNetAssemblyCompiler '..\..\..\bin\Jedi.IO.dll'} {%DelphiDotNetAssemblyCompiler '..\..\..\bin\Jedi.System.dll'} uses System.Reflection, System.Runtime.CompilerServices, System.Windows.Forms, WinFormMain in 'WinFormMain.pas' {WinFormMain.TWinFormMain: System.Windows.Forms.Form}; {$R *.res} {$REGION 'Program/Assembly Information'} [assembly: AssemblyTitle('example.StreamOfValueType')] [assembly: AssemblyDescription('Example of the Jedi.IO.StreamOfValueType class.')] [assembly: AssemblyConfiguration('')] [assembly: AssemblyCompany('Project JEDI')] [assembly: AssemblyProduct('JEDI.NET library')] [assembly: AssemblyCopyright('Copyright © 2004 - 2005 Project JEDI')] [assembly: AssemblyTrademark('')] [assembly: AssemblyCulture('')] [assembly: AssemblyVersion('1.0.0.0')] [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile('')] [assembly: AssemblyKeyName('')] {$ENDREGION} [STAThread] begin Application.Run(TWinFormMain.Create); end. --- NEW FILE: example.StreamOfValueType.bdsproj --- (This appears to be a binary file; contents omitted.) --- NEW FILE: WinFormMain.resx --- (This appears to be a binary file; contents omitted.) |