Hi all, hope you can solve my problem. First an explanation of my setup. A codeunit is inserting 100 records in an temp table: 1,A,DATA 2,A,DATA 3,A,DATA 4,A,DATA 5,A,DATA … 99,A,DATA 100,A,DATA Also some other “K” records 1,K,DATA 1,K,DATA 3,K,DATA A filter is set on “A” so only the 100 records are selected and a form is called with the temp table. The form is showing all 100 records ok. When a user clicks on a button I need to read a “K” record and do something. This doesn’t work because only “Rec” can see all the records. A second var:record can not see the data. I can use Rec to get to the “K” records but then my screen changes. Something that i don’t want. In the codeunit I defined the temp table as an array. This way I had 2 pointers to the same data. Do you know a way to have a second pointer to the temp table on a form? Thx in advance
You might try something like this… Create a function on the form to pass the temp to a global temp array on the form. Create a form variable in your codeunit and call this function with your unfiltered temp record. Then run the form variable without using the record. ---------------------------------------------------------- Procedure InitializeForm(VAR NewTempRec) ---------------------------------------------------------- TempRecord[1].RESET; TempRecord[1].DELETEALL; IF NewTempRec.FIND(’-’) THEN REPEAT TempRecord[1].INIT; TempRecord[1] := NewTempRec; TempRecord[1].INSERT; UNTIL NewTempRec.NEXT = 0; TempRecord[1].Filtergroup(2); TempRecord[1].Setrange([FieldName],‘A’); TempRecord[1].Filtergroup(0); Then modify the OnFindRecord and OnNextRecord triggers on the form to navigate the temp. ---------------------------------------------------------- Form - OnFindRecord(Which : Text[1024]) : Boolean ---------------------------------------------------------- TempRecord[1] := Rec; IF NOT TempRecord[1].FIND(Which) THEN BEGIN CLEAR(Rec); EXIT(TRUE); END; Rec := TempRecord[1]; EXIT(TRUE); ---------------------------------------------------------- Form - OnNextRecord(Steps : Integer) : Integer ---------------------------------------------------------- TempRecord[1] := Rec; CurrentSteps := TempRecord[1].NEXT(Steps); IF CurrentSteps <> 0 THEN Rec := TempRecord[1]; EXIT(CurrentSteps); Now you should be able to use TempRecord[2] to get at your ‘K’ records without changing the form view. I have not tested this but it should work. NOTE: The temp record you use must not contain any data in the database.
Something simular I already checked and does work, thanks anyway The temp table can contain more then 100.000 records and it takes to much time to create a copy.
Ok, not possible then. Now trying to build a workaround
Depending on the way your CU opens the form, you could create a function on the form which is called before the form is actually opened. You can pass an additional pointer to the temp record to a global form variable with this function. This works only if the form is opened via a form variable.
Erik, I think you can write something like that in OnPush trigger: rec2.COPY(Rec); SETRANGE(field2,‘K’); //do what you need COPY(rec2); Then form is not changing…
quote:
Originally posted by xorph
Depending on the way your CU opens the form, you could create a function on the form which is called before the form is actually opened. You can pass an additional pointer to the temp record to a global form variable with this function. This works only if the form is opened via a form variable.
Is it possible to open form via form variable using temp record? I tried tempform.SETRECORD(temprec) and tempform.SETTABLEVIEW(temprec), but form runs not on temp record. I thought it’s possible only using commands FORM.RUN(XXX,temprec) or FORM.RUNMODAL(XXX,temprec)
Have you considered using two sub-forms - filtering the view on each sub-form to ‘A’ or ‘K’ and controling the display of data through the Visible property?
quote:
Originally posted by Viktoras
I tried tempform.SETRECORD(temprec) and tempform.SETTABLEVIEW(temprec), but form runs not on temp record.
You are correct, it doesn’t work [:(!] Not very nice… [B)]
quote:
Originally posted by Viktoras
Erik, I think you can write something like that in OnPush trigger: rec2.COPY(Rec); SETRANGE(field2,‘K’); //do what you need COPY(rec2); Then form is not changing…
Noop, doesn’t work when “Rec” is a temp table.
quote:
Originally posted by ajhvdb
quote:
Originally posted by Viktoras
Erik, I think you can write something like that in OnPush trigger: rec2.COPY(Rec); SETRANGE(field2,‘K’); //do what you need COPY(rec2); Then form is not changing…
Noop, doesn’t work when “Rec” is a temp table.
I didn’t mean that with copy command you can copy temp record. Just copy current temp record with current filters and, after processing some code, copy it back to temp record. I tested such situation, but I don’t know what do you want to do on OnPush trigger.
F.i. when a user pushes the button on rec(3,A,DATA) the program must find the rec2(3,K,DATA) and with this data show a new window. Because the var rec is a temp table, the var rec2 can NOT look in the temp table. Hope this explains it a bit more
You say that the performance of creating a copy of the temp is an issue. I don’t know if this is an option, but could you have the form create the temp table?
quote:
Originally posted by ajhvdb
F.i. when a user pushes the button on rec(3,A,DATA) the program must find the rec2(3,K,DATA) and with this data show a new window. Because the var rec is a temp table, the var rec2 can NOT look in the temp table. Hope this explains it a bit more
then I don’t understand why my code is bad… rec2.COPY(Rec); SETRANGE(field1,field1); SETRANGE(field2,‘K’); IF FIND(‘-’) THEN BEGIN //looking for entry in temp rec rec3 := rec; COPY(rec2); //must do this before running other form FORM.RUN(YYY,rec3); END; COPY(rec2);
Zarryn, No, not possible. Viktoras, Because the line “if rec.find …” will change the view on the form.
How about inserting the actual records in that table per USERID. I mean the Part of primary key will be USERID. Now instead temporarily creating the records, create the actual records in the table. that way, you can do whatever you want to do with that, and when you run that again, delete all the records for that user.
quote:
Originally posted by ajhvdb
Viktoras, Because the line “if rec.find …” will change the view on the form.
But I tested - it’s not changing. Maybe I can’t get your situation… If I do not restore rec before calling another form, then record is changing…
That’s my current workaround, Naveen.
quote:
Originally posted by Viktoras But I tested - it’s not changing. Maybe I can’t get your situation… If I do not restore rec before calling another form, then record is changing…
Not only the “find” line is changing the view but the first “setrange” line is doing it also. This is standard behaviour… Whatever you do with “Rec” will change your view.
Take a look at Form 7347. The OnFindRecord and OnNextRecord triggers have been modified to only display records that pass a test. You might be able to use this code pattern to display your A recs without having to filter out your K recs. Perhaps something like this might work?