Units

How to write your own unit?
Please include all specs.
like everything i mean, thanks.

Comments

  • : How to write your own unit?
    : Please include all specs.
    : like everything i mean, thanks.
    :

    Here is a pretty basic unit showing some of the structures in a unit:

    [code]
    unit MyUnit;

    interface

    uses
    Crt, Unit2, Unit3, Etc;

    {
    Other units will be able to read/write
    to the variables in the interface section
    }
    var
    MyPublicVariable: Boolean;

    {
    Other units will be able to call the
    functions/procedures declared in the
    interface section
    }
    function MyPublicFunction: Boolean;

    implementation

    {
    Other units will not be able to read/write
    to the variables in the implementation section
    }
    var
    MyPrivateVariable: Boolean;

    {
    MyPrivateFunction was not declared in the
    interface section, so only other functions
    and procedures in this unit may call it
    }
    function MyPrivateFunction: Boolean;
    begin
    MyPrivateFunction := MyPrivateVariable;
    end;

    {
    MyPublicFunction was declared in the
    interface section, so other units may
    call it
    }
    function MyPublicFunction: Boolean;
    begin
    MyPublicFunction := MyPublicVariable;
    end;

    {
    This is the initialization section, and is run
    before any other code (except for initialization
    sections in other units, which may or may not
    be run first)
    }
    begin
    MyPublicVariable := False;
    MyPrivateVariable := True;
    end.
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion