This is my first real class and time using property's....
I think I coded it right but I went by what I knew and read from the tutorial in the Wiki..
My problem is when the code compiles it just closes(CLI) and I'm not sure why.. I made 2 units. One to create a file type and one to read it...
To read the document
{*Unit Used For opening and reading ZAX files...
ZAX Devolopment by Adam N.Andujar.*}
unit ZAX;
{*ZAX STATEMENTS
#ZAX to say its a ZAX file
%Author[Author Name here]
%About[About Document Here]
%BOD* Start the document
*EOD% Close the document
*}
{$mode objfpc}{$H+}
interface
uses
Classes,SysUtils,LCLProc;
Type
TZAXHeader = Record//File header
ZHead:String;
ZAuthor:String;
ZAbout:String;
ZBody:String;
end;
TZaxFile = File Of TZAXHeader;//File Type
TOpenZax = Class(TObject)
Private
Zax:TZaxheader;
F:TZaxFile;
FileN:String;
Function GetAuthor:String;//Returns the Author
Function GetBody:String;//Resturns the body
Function GetAbout:String;//returns about
Function GetIsDoc:Boolean;//Check for #ZAX
Public
Property IsDoc:Boolean Read GetIsDoc;//If the documents first line isnt #ZAX it wont be a ZAX doc though will still be read
Property Body:String Read GetBody;//The whole file document
Property Author:String Read GetAuthor;//Property to hold the author
Property About:String Read GetAbout;//Property to hold about the document
Constructor Create(const ZF:String);virtual;//Load an existing ZAX file
end;
implementation
Function TOpenZax.GetIsDoc:Boolean;
begin
IF(Zax.ZHead = '#ZAx')Then Result := True Else Result := False;
end;
Function TOpenZax.GetAbout:String;
begin
Result := GetPart('[',']',ZAX.ZAbout);
end;
Function TOpenZax.GetAuthor:String;
begin
Result := GetPart('[',']',Zax.ZAuthor);
end;
Function TopenZax.GetBody:String;
begin
Result := GetPart('%BOD*','*EOD%',Zax.ZBody)
end;
Constructor TOpenZax.Create(const ZF:String);
begin
FileN := ZF;
AssignFile(F,FileN);
Reset(F);
Read(F,Zax);
end;
end.
To create the document:
{*Unit used for creating ZAX files. Devolopment by Adam N.Andujar*}
unit ZAXCreate;
{$mode objfpc}{$H+}
interface
uses
Classes,SysUtils,LCLProc,ZAX;
Type
TMakeZAX = object
Private
F:TZAXFile;
NewZax:TZAXHeader;
FileN:String;
Function ReadAbout:String;//Read about
Function ReadBody:String;//read the body
Function ReadAuthor:String;//Read the author
Procedure WriteBody(const S:String);virtual;// Add the body
Procedure WriteAuthor(const S:String);virtual;//Add the author
Procedure WriteAbout(const S:String);virtual;//Add about the document
Public
Property Body:String Read ReadBody Write WriteBody;
Property About:String Read ReadAbout Write WriteAbout;
Property Author:String Read ReadAuthor Write WriteAuthor;
Constructor Create(const FN:String);//Set all the stuff :P
Procedure MakeFile;//Create the file
end;
implementation
Procedure TMakeZax.MakeFile;
begin
Rewrite(F);
Write(F,newZax);
CloseFile(F);
end;
Function TMakeZAX.ReadAbout:String;
begin
Result := About;
end;
Function TMakeZAX.ReadAuthor:String;
begin
Result := Author;
end;
Function TmakeZAX.ReadBody:String;
begin
Result := Body;
end;
Constructor TMakeZax.Create(const FN:String);
begin
FileN := Fn;
AssignFile(F,FileN);
Author := '';
About := '';
Body := '';
end;
Procedure TMakeZAX.WriteAbout(const S:String);
begin
About := S;
NewZax.ZAbout := About;
end;
Procedure TMakeZAX.WriteBody(const S:String);
begin
Body := S;
NewZax.ZBody := Body;
end;
Procedure TMakeZAX.WriteAuthor(const S:String);
begin
Author := S;
NewZax.ZAuthor := Author;
end;
end.
The projects main program:
program project1;
{$mode objfpc}{$H+}
uses
Classes,SysUtils,ZAX,ZAXCreate;
Var
OpenZax:TOpenZAX;
make:TMakeZax;
begin
Make.Create('Z.zax');
Make.Author := 'Adam';
Make.About := 'Something';
Make.Body := 'DJHADJAFK JAFNKJ AANFKJABRUHFAHNJVNKJFKJABKJN';
Make.MakeFile;
OPenZax.Create('Z.zax');
Writeln(OPenZax.Author);
Writeln('');
Writeln('');
Writeln(OpenZax.Body);
Readln;
end.
(I know the TMakeZax is still just an Object but I was gonna convert it when I fixed this problem)
![Smiley :)](/Smileys/ExcellentSmileys1/smile.gif)