Recent

Author Topic: How do i use units in my program?  (Read 9004 times)

captian jaster

  • Guest
How do i use units in my program?
« on: February 28, 2010, 01:57:45 am »
I know it would be in the uses section but i mean units i made myself.
Code: [Select]
uses MyUniti wanna know how to do it
i think itll help me

davesimplewear

  • Sr. Member
  • ****
  • Posts: 314
    • Davids Freeware
Re: How do i use units in my program?
« Reply #1 on: February 28, 2010, 07:00:05 am »
do as you put, seperate each unit with a comma, terminate the statement with a semi-colon eg:
Code: [Select]
uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs;
All things considered insanity seems the best option

picstart

  • Full Member
  • ***
  • Posts: 236
Re: How do i use units in my program?
« Reply #2 on: March 01, 2010, 03:25:09 am »
Things to be aware of the uses statement can be in the implementation section or it can be in the interface section. Now if unit1 and unit2 need to share anything  then unit1 (I'm pretty sure needs) to be in unit2's implementation uses and unit2 needs to be in unit1's implementation uses.
The interface uses will generate circular errors if they are there.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8421
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How do i use units in my program?
« Reply #3 on: March 01, 2010, 07:59:59 am »
I think the OP wants to know how to create units. Jsut google for: pascal unit tutorial

captian jaster

  • Guest
Re: How do i use units in my program?
« Reply #4 on: March 01, 2010, 07:07:51 pm »
I think the OP wants to know how to create units. Jsut google for: pascal unit tutorial

Right, thank you! i looked up the pascal unit tut and got some stuff insome wild other language. i understand making the unit but i dont know how to execute a code from the unit

captian jaster

  • Guest
Re: How do i use units in my program?
« Reply #5 on: March 01, 2010, 07:43:55 pm »
OK heres what i dont get..
Code: [Select]
unit Console;

interface

uses CRT,SysUtils,Windows,Dos,Classes;

const
 ERROR1 = 'File Not Found!';
 ERROR2 = 'Unkown Error!';

var
 Command : String;

implementation

Procedure HELP;
BEGIN
  writeln('EXIT, Close the Program');
  writeln('[OPEN]MENU, Go to the Main menu');
END;

BEGIN
  ClrScr;
  GotoXY(30,30);
  writeln('Xhydriks Version 0.00');
  writeln('By Adam N.Andujar');
  Repeat
  writeln('Awaiting Command..');
  readln(Command);
  until(Command = 'EXIT');
END.
Code: [Select]
program Xhydriks;

uses CRT,Console;

var
 sel : string;


BEGIN
  writeln('Welcome!');
  writeln('1. Console');
  writeln('2. Exit');
  Repeat
  sel := Readkey;
  if sel = '1' then Console
  else writeln('ERROR!, only input listed chars');
  Until(sel = '2');
END.

 
it say identifier expected bu else found when i try to compile the xhydriks

Peter_Vadasz

  • New Member
  • *
  • Posts: 35
Re: How do i use units in my program?
« Reply #6 on: March 01, 2010, 08:54:27 pm »
Try this:

Unit:
Code: [Select]
unit consoleu;

interface

uses crt;

const
 ERROR1 = 'File Not Found!';
 ERROR2 = 'Unkown Error!';

 procedure Console;

implementation

var
 Command : String;
 
Procedure HELP;
BEGIN
  writeln('EXIT, Close the Program');
  writeln('[OPEN]MENU, Go to the Main menu');
END;

procedure Console;
BEGIN
  ClrScr;
  GotoXY(30,30);
  writeln('Xhydriks Version 0.00');
  writeln('By Adam N.Andujar');
  writeln;
  HELP;
  Repeat
    writeln('Awaiting Command..');
    readln(Command);
  until(Command = 'EXIT');
END;

END.

program:
Code: [Select]
program Xhydriks;

uses CRT,Consoleu;

var
 sel : string;

begin
  writeln('Welcome!');
  writeln('1. Console');
  writeln('2. Exit');
  Repeat
  sel := Readkey;
  if sel = '1' then Console
  else writeln('ERROR!, only input listed chars');
  Until(sel = '2');
end.
OS: Ubuntu 12.04.2 32 bit
Lazarus: 1.0.8
FPC: 2.6.2

captian jaster

  • Guest
Re: How do i use units in my program?
« Reply #7 on: March 01, 2010, 09:14:03 pm »
Thank you!

Bart

  • Hero Member
  • *****
  • Posts: 4709
    • Bart en Mariska's Webstek
Re: How do i use units in my program?
« Reply #8 on: March 02, 2010, 04:02:20 pm »
Note: what happens if the user presses '2' ?
Try it.
Do you really want that to happen?

Bart

 

TinyPortal © 2005-2018