
06-28-2012, 12:39 PM
|
|
Junior Member
|
|
Join Date: Jun 2012
Posts: 1
|
|
Stack over flow ... what is wrong with the function
Type and variable used
Quote:
type
// Worktype
AWtype = record
Name:String;
Colour:TColor;
WtypeCodeName:Integer;
StartHeight ouble;
EndHeight ouble;
end;
// Site space properties
TRecordSiteProperties = record
PrismWType:array [1..MaxAWtype] of AWtype ;
{store set of sub worktype of a prism in sequence}
MaxSubWorkType:Integer;
MainWorkType:Integer;
MainWorkStartHeight ouble;
MainWorkEndHeight ouble;
CurrentWork : integer;
ResourceNumber : integer;
ResourceSpaceType : Integer;
/
WorkSurface : Double;
end;
TSiteTaskMatrix = array [1..MaxSiteColumn,1..MaxSiteRow] of TRecordSiteProperties;
//Resource space properties
ACoordinate = record
ACol,ARow:integer;
end;
AResourceSpace = record
SpaceType:integer;
SpaceVerticalMax, SpaceVerticalMin:double;
End;
AnAbility=record
RWType:integer;
OptimumProductivity:double;
Efficiency:integer; //scale from 1 to 100
end;
AResource=record
ResourceNumber:integer;
Name:string;
Abilities:array[1..MaxResourceAbility] of AnAbility;
NumberOfAbilities : Integer;
TheSpace:array [1..MaxResourceCol, 1..MaxResourceRow] of AResourceSpace;
ResourceWorkSpaceHeightMin , ResourceWorkSpaceHeightMax : Double;
ResourcePhysicalSpaceHeightMin , ResourcePhysicalSpaceHeightMax : Double;
ResourceSafetySpaceHeightMin , ResourceSafetySpaceHeightMax : Double;
MaxRowUsed,MaxColUsed:integer;
end;
TAvailableResource = Array [1..MaxAvialableResource] of AResource ;
TArrayOfInt = Array [1..MaxAvialableResource] of integer;
//Global variables are used through out the program procedures
var
Form1: TForm1;
PVNumberAvailableMainWorkType : Integer;
PVSite:TSiteTaskMatrix;
CurrentRow, CurrentCol : integer;
MaxHi,MinLow,HeightDiff:real;
PVAvailableResource : TAvailableResource;
PVNumberAvailableResource : Integer;
ProjectTime : Double;
CapableResource : TArrayOfInt; //Store resouce code name to be placed on PVSite
|
The function 1
Quote:
Function ChooseResourceForSiteWorkType
(TheSite:TSiteTaskMatrix;AllLoadResource:TAvailabl eResource;
MaxSiteCol,MaxSiteRow,AvialableResource,k:Integer) : TArrayOfInt;
//trying to do this function with button1 testing ... not working yet... <----------------
// Try do loop here in function
//try do loop in procedure
//
Var
i,j,SiteCol,SiteRow,l,m :Integer;
CapRes : TArrayOfInt;
Begin
k:=0;
for SiteCol := 1 to MaxSiteColumn do
for SiteRow := 1 to MaxSiteRow do
for i := 1 to AvialableResource do
for j:= 1 to AllLoadResource[AvialableResource].NumberOfAbilities do
Begin
if
(TheSite[SiteCol,SiteRow].MainWorkType <> 0)
and
(TheSite[SiteCol,SiteRow].CurrentWork =
AllLoadResource[AvialableResource].Abilities[j].RWType)
and
(CheckIfSameNumberInArray(CapRes,(AllLoadResource[AvialableResource].ResourceNumber)))
then
k:= k+1;
CapRes[k] := AllLoadResource[AvialableResource].ResourceNumber;
End;
{
for i := 1 to AvialableResource do
Begin
for j:= 1 to AllLoadResource[AvialableResource].NumberOfAbilities do
Begin
for SiteCol := 1 to MaxSiteColumn do
for SiteRow := 1 to MaxSiteRow do
Begin
if
(TheSite[SiteCol,SiteRow].MainWorkType <> 0)
and
(TheSite[SiteCol,SiteRow].CurrentWork =
AllLoadResource[AvialableResource].Abilities[j].RWType)
then
for l:= 1 to AvialableResource do
Begin
if
(CapRes[AvialableResource]<>AllLoadResource[AvialableResource].ResourceNumber)
then
k:= k+1;
CapRes[k] := AllLoadResource[AvialableResource].ResourceNumber;
End;
End;
End;
End;
}
// for m := 1 to AvialableResource do
// Begin
// Result[m] := CapRes[m];
// End;
Result := CapRes;
End;
|
Function 2
Quote:
function CheckPosition(x,y,RNumber:integer; Site:TSiteTaskMatrix):Integer; //NOT WORKING !!!
// site position (x, y)
var
i,j : Integer;
begin
//This routine should take the value 0 if the resource is OK in position x,y
// and 1,2 or 3 otherwise 1=problem safety, 2=problem physical, 3=problem work
CheckPosition:=0; {set this to 0 as the default situation. i.e. possible to work}
For i:=1 to PVAvailableResource[RNumber].MaxColUsed do
Begin
For j:=1 to PVAvailableResource[RNumber].MaxRowUsed do
Begin
// 0 = Unused 1 = Work 2 = Physical 3 = Safety
//1 Working space
If (PVAvailableResource[RNumber].TheSpace[i,j].SpaceType=1)
and (Site[x+i-1,y+j-1].ResourceNumber = 0)
and (Site[x+i-1,y+j-1].MainWorkType <> 0)
then
Begin
CheckPosition := 0
end;
//2 Physical space
If (PVAvailableResource[RNumber].TheSpace[i,j].SpaceType=2)
and (Site[x+i-1,y+j-1].ResourceNumber = 0)
then
Begin
CheckPosition := 0
End;
//3 Safety space
If (PVAvailableResource[RNumber].TheSpace[i,j].SpaceType=3)
and (Site[x+i-1,y+j-1].ResourceSpaceType = (3 or 0))
then
Begin
CheckPosition := 0
End;
End;
End;
End;
|
I am not sure what i should be posting... i have also attached full program coding
Last edited by oversleep; 06-30-2012 at 05:56 PM.
Reason: spelling
|