mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-25 10:17:31 +01:00
codetools: added example for nested classes
git-svn-id: trunk@29032 -
This commit is contained in:
parent
a6965afecd
commit
5aabc7242b
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -471,6 +471,7 @@ components/codetools/examples/scanexamples/indentation.pas svneol=native#text/pl
|
|||||||
components/codetools/examples/scanexamples/methodjump1.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/methodjump1.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/missingh2pasdirectives.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/missingh2pasdirectives.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/modemacpas.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/modemacpas.pas svneol=native#text/plain
|
||||||
|
components/codetools/examples/scanexamples/nestedclasses.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/overloadedfunction.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/overloadedfunction.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/publishedvars.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/publishedvars.pas svneol=native#text/plain
|
||||||
components/codetools/examples/scanexamples/resourcetest1.pas svneol=native#text/plain
|
components/codetools/examples/scanexamples/resourcetest1.pas svneol=native#text/plain
|
||||||
|
|||||||
70
components/codetools/examples/scanexamples/nestedclasses.pas
Normal file
70
components/codetools/examples/scanexamples/nestedclasses.pas
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
program Project1;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
{$modeswitch advancedrecords} // {$mode delphi} has it automatically
|
||||||
|
|
||||||
|
// 1. advanced classes/objects
|
||||||
|
|
||||||
|
type
|
||||||
|
TClass1 = class
|
||||||
|
type
|
||||||
|
Int = Integer;
|
||||||
|
TInnerClass = class
|
||||||
|
public
|
||||||
|
F: Int;
|
||||||
|
procedure Test;
|
||||||
|
end;
|
||||||
|
const
|
||||||
|
CInt: Int = 5;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TClass1.TInnerClass.Test;
|
||||||
|
begin
|
||||||
|
WriteLn(F);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// 2. advanced records
|
||||||
|
type
|
||||||
|
TRec1 = record
|
||||||
|
private
|
||||||
|
type
|
||||||
|
Int = Integer;
|
||||||
|
var
|
||||||
|
F: Int;
|
||||||
|
const
|
||||||
|
DefaultF: Int = 1;
|
||||||
|
public
|
||||||
|
function GetF: Int;
|
||||||
|
procedure SetF(const Value: Int);
|
||||||
|
// full list of operators see in tests/test/terecs6.pp
|
||||||
|
class operator Inc(Rec: TRec1): TRec1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRec1.GetF: Int;
|
||||||
|
begin
|
||||||
|
Result := F;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRec1.SetF(const Value: Int);
|
||||||
|
begin
|
||||||
|
F := Value;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class operator TRec1.Inc(Rec: TRec1): TRec1;
|
||||||
|
begin
|
||||||
|
Result.F := Rec.F + 1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// 3. generics
|
||||||
|
type
|
||||||
|
generic TArr<T> = array[0..2] of T;
|
||||||
|
generic TProc<T> = procedure(Arg: T);
|
||||||
|
generic TRecG<T> = record
|
||||||
|
F: T;
|
||||||
|
end;
|
||||||
|
// delphi generic please see in:
|
||||||
|
// tgeneric28.pp, tgeneric29.pp, tgeneric32.pp, tgeneric34.pp
|
||||||
|
|
||||||
|
begin
|
||||||
|
end.
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user