How to limit File to a Single record

Tags: #<Tag:0x00007f0b7c9cc690> #<Tag:0x00007f0b7c9cc4d8>

Hi Guys,

I need to declare 0 dimensioned array into clarion, how can i declare an array or variable and use it where it saves only 1(one) record and does not allow more then one record to be saved

I am trying to save record but it isn’t displaying and variable is saving multiple values.

I tried dimmed array declaration but it’s still saving multiple values in an array.

Database used is Top Speed

Not clear enough, but…

array1  LONG, DIM(1)  !- can hold only 1 value in array1[1]
var1    LONG          !- no DIM attribute, can hold 1 value in var1

I am confused by your question. Do you really want an array, as in DIM()? Or are you simply trying to prevent the occurrence of more than one record in the table? Dimensions have no bearing on the number of records in a table.

Are you using ABC, handcode, or the Clarion templates?

2 Likes

@jslarve

Yes i want to have only one record in a table and the template us ABC

I usually would create a source procedure to call my update form.

Keep in mind that I am typing from memory and have not compiled what’s below :slight_smile:

Something like this in your source procedure - salt to taste:

 IF Access:MyTable.Open() = LEVEL:Benign
     Access:MyTable.UseFile()
     SET(MyTable)
     IF Access:MyTable.Next() <> LEVEL:Benign !No record exists yet
           !Prime your fields to default values here
           IF Access:MyTable.TryInsert() <> LEVEL:Benign
                MESSAGE('Cannot insert new record.||' & ERRORCODE())
                RETURN
           END
     END
      !Now we can assume/hope that the record has been created or fetched successfully
     GlobalRequest = ChangeRecord
     YourUpdateForm !Call your update form here.
     IF GlobalResponse = RequestCompleted
         !Saved the record
     ELSE
         !Cancelled, or there was a problem saving
     END
     Access:MyTable.Close()
 ELSE
     MESSAGE('Cannot open table')
 END
1 Like

You would want a WATCH(File) before the NEXT() so the form Optimistic Concurrency would work.

I usually let the Form procedure do the Insert as so the PrimeFields can work as typical from DCT default or template entires. I have not used ABC much recently so this might not be correct:

IF Access:MyTable.Open() = LEVEL:Benign
    Access:MyTable.UseFile()
    SET(MyTable)
    WATCH(MyTable) !<-- Form Optimistic Concurrency needs 
    IF Access:MyTable.Next() = LEVEL:Benign THEN
       GlobalRequest = ChangeRecord
    ELSE
       GlobalRequest = InsertRecord
    END 
    YourUpdateForm() !Call your update form here.
    IF GlobalResponse = RequestCompleted
        !Saved the record
    ELSE
        !Cancelled, or there was a problem saving
    END
    Access:MyTable.Close()
ELSE
    MESSAGE('Cannot open table')
END
1 Like

Hi Carl -

The PrimeFields method that gets called in the update form is part of the WindowManager object. I don’t think the dictionary has anything to do with what gets done with that. I always thought of it as an extra place to set stuff up after the record had already been created/primed by the browse object.

The FileManager.PrimeRecord() does make use of the dictionary stuff, I think. It gets called from the browse (if there is a browse). I suppose you could try Access:YourTable.PrimeRecord() , but for single record scenarios, I’ve always put the code in that setup code. You have a good point though.

In my experience, usually a single record table is written once and read often. But I suppose it could be important to support the optimistic concurrency issues too for some situations.

Best wishes

@vedant I think you’re using the wrong terminology.
You seem to use ‘Array’ as a database table and ‘element’ as a record. Either that or I’m confused as well.
In Clarion they are completely separate things.
You can use a unique index key on a topspeed table to limit adds. If the key field is zero you can’t add another with a zero.

1 Like

An example I can think of is Payroll where some Tax rates/limits are in a single record table. At the end of the year it is common for multiple people to open the record as they discuss what rates are correct. It seems like most people want to always press OK (the form template will not save an unchanged record, but dev code in the wrong place can accidentally change the record).

E.g. Don starts to change the rates and realizes this is more work than he wants to do, so Don calls Steven (who can spell Circular E) who opens the form, enters the correct rates and saves. If Don clicks OK he overwrites Steve unless WATCH gives him an error 98.

In Legacy PrimeFields is a routine generated into the Form that has some variables set from the DCT Initial Value.

1 Like

Exactly what i was looking for…