practical copy Flashcards
Variable to store dates
DateTime
Prefix for DateTime variable
t
Methods for assigning date to DateTime variable
Convert from string
Convert from integer
Convert to DateTime from string
StrToDateTime(‘dd/mm/yyyy hh:mm:ss’);
Convert to DateTime from integer
EncodeDateTime(yyyy, mo, d, h, m, s);
Functions returning DateTime values
Yesterday - 00:00:00 of yesterday
Date - 00:00:00 of today
Tomorrow - 00:00:00 of tomorrow
Now - current date and time
How to do calculations with DateTime variable
Add/subtract number (or fractions of) DAYS to it
Functions performed on DateTime values
Type keywords (day, year, month, FormatSettings.Long) into ctrl+spacebar ; will usually return integer value
How to format DateTime
FormatDateTime(), for sFormat use letters : YMDH NSZ with - between
How to declare an array
Array[first..last] of type;
Steps to working with TextFiles
- Declare logical file in variable
- Assign physical file to logical file
- Set logical file to correct state
- Use file
- Close file
Declare file variable
fFile : TextFile
Assign file
AssignFile(fFile, ‘’)
States to set file to ***** include diff
Reset
Rewrite
Append
Close file
CloseFile(fFile)
How to read from textfile
Reset
ReadLn(fFile, sOutput) - moves to next line
How to write to textfile
Rewrite/append
WriteLn(fFile, sInput) - moves to next line
Write(fFile, sInput) - doesn’t move to next line
How to loop through textfile
Eof(fFile)
Input and output of methods
Parameters and return values
Difference between function and procedure
Both accept parameters but only functions return a value
Declare procedure
procedure ProcedureName(parameterName : type);
ctrl+shift+C
What do you use parameters as
Variable in method
How to use procedure
Type in name and input parameters
Declare function
function FunctionName(parameterName: type) : type;
Ctrl+shift+C
How to use function
Assign value to Result variable
within method
Type in name and input parameters and use result like assign it to variable or smth
Scope of methods and where to declare them
Declare after implementation BEFORE automatically created procedures
Use global variables : frmForm.component to reference them
Dynamic user interface
Components created using code in runtime
Types of dynamic components
Visual
Interactive
How to create non-interactive visual dynamic component
- declare empty var of component’s class (vVariable : TType) - in global var when in doubt
- create component (component.create(parent - can say self)) assigned to said variable
- use var (NOT COMPONENT) to assign values to prop of component - .PARENT FIRST (can be self)
how to insert image to be displayed
bitmap.createFromFile - string
what is an interactive component
has events during run time like onClick events
how to use interactive component
- create as would visual component
- declare procedure in public : add (Sender: TObject) - EXACTLY, dont change TObject to component
- assign procedure name to event property of component
how to write data to a database (through code)
tables component methods:
- append : adds record at end and selects it (NOT ADDS VALUE TO, DO AFTER - think of it as setting text file up to be used)
- insert : adds record after currently selected and selects it
NB!
- POST!!! saves changes after data changed in db
how to add data to created record
table[‘fieldName’] := value; (puts into selected field)
post OBVI
how to read data from table
- select first record (tbl.first)
- while loop to scroll through records till tbl.eof (EVEN THOUGH NOT A FILE HA)
- read record - tbl[‘fieldName’]
- go to next record (tbl.next)
WITH ALL THINGS OF USING TABLES REMEMBER!!!!!!!
put DBModule name before tblName OR IT WONT WORK
you could even be a cool kid and use WITH dbmName do like a SUPER COOL KID
how to edit existing data in db
- find + select record wanting to edit
- set tbl to edit mode (tbl.Edit)
- set new values as shown before
- POST!!
how to find record in DB
tbl.Locate(‘fieldName’, searchValue, []) - selects that record and do what you will with it after
generally with setting modes of tbl…
do right before doing it - like put tbl.edit right before editing ykyk - idk if this is actually a thing but i remember it once
what is a class
data type describing attributes and behaviour of object to be created from it (BLUEPRINT)
object
INSTANCE of the class - like a model formed from the blueprint
attributes
data fields of class (PROPERTIES)
behaviour
code providing interaction with attributes - INTERACTIONS with object made up of attributes, how can use attributes
encapsulation
grouping of attributes and behaviour into one entity (object of type class)
what is OOP used for?
- independent isolated code
- reusable code
- improved integrity
how to declare a class
- create unit file for class code
type
ClassName = class(optional baseClass)
private
declare attributes + private methods
public
declare public methods
access specifier
where accessible
- private: inside class
- protected: inside class / classes based on class
- public: any program where class used
- published: public but available in object inspector
remember for working with classes!
type class code in class unit!
types of class methods
getter (accessor)
setter (mutator)
constructor
ToString
other auxiliary (helper) methods
type double
real with more digits for fraction
class diagram
identity (name)
attributes (state)
name : type;
methods (behaviour)
declarations of methods
in total forms encapsulation
include private/public with -/+