当前位置:网站首页>Why can't the form be closed? The magic of revealing VFP object references
Why can't the form be closed? The magic of revealing VFP object references
2022-06-25 11:44:00 【VFP of Garfield】
Yesterday was 2022 The first live broadcast class ,XINJIE The teacher gave the lecture , Cats and cats have training classes outside , Just show your face for two minutes , I couldn't watch the whole journey , I can only watch the playback .
This is our harvest , So that everyone's software can be packaged , More classy , Of course, we also need to get more premium .
Come to Garfield's community , There have been too many fox friends surpassing me , So the next will invite you to share , Listen to their knowledge sharing , Your apple + My apple , In exchange , Or an apple , But knowledge , Your knowledge + My knowledge = Double knowledge .
Many fox friends can't write classes yet , Can't use objects , Let's talk about the basics today . The following example is from the network .
“ Object reference ” The concept of
What is? “ Object reference ” Well ? such as , Now we have a form form1, There is a page box on the form pageframe1, There is a table on the first page of the page box grid1, Now? , I want to set the title of the first column to “ First column ”, Set the background color to gray , Under normal circumstances , We have to enter long object hierarchies such as :
thisform.pageframe1.page1.grid1.column1.header1.caption = ” First column “
thisform.pageframe1.page1.grid1.column1.BackColor = RGB(192,192,192)
Use With……EndWith Structure can make the above troublesome input a little easier :
WITH thisform.pageframe1.page1.grid1.column1
.header1.caption = " First column "
.BackColor = RGB(192,192,192)
ENDWITH
Here is the requirement that the code must be continuous , What to do if it is not continuous ?
Put this object into a variable , The variable becomes a part of the object .
LOCAL oColumn ’ Create a pair of tables Column1 References to objects
oColumn = thisform.pageframe1.page1.grid1.column1
oColumn.header1.caption = ” First column “
oColumn.BackColor = RGB(192,192,192)
Here to create oColumn Variable , Then assign it a value Column1 object , In fact, it is not really assigned , In fact, it's just a point , This object is still in its original position , This object references , such , We can operate directly Column1 Object oColumn The variable .
Yes oColumn Any operation of will be reflected in Column1 On the object .
Object references are not equal to ordinary variables
it seems , This so-called “ Object reference ” Variables are no different from ordinary variables . Let's prove it .
Continue with the previous example , However, it is necessary to put the Local Change it to Public, Then put this code into the form's Init Method to go , Run this form and close it , See what happened .
“ The form cannot be closed ! Is it a crash ? Let me press Ctrl+Alt+Del try ……”
“NO! Don't do that !”, No crash , It's just that the reference of the object is making trouble . You can open the debugger to see what happened : stay Local In the window , The variable name of the form is still , Its type is “O”, But its value is already “.NULL.”, in other words : The form has actually been released . And below oColumn Variables are different , Its type is “O”, Value is “ object ”!
reason : Anything created in the form Public Variables are not automatically released when the form is released .
Because we will oColumn Object declared as Public 了 , therefore oColumn Object was not released after closing the form .
We can see it from here : Using the technology of object reference , You can access any object on the form , This is beyond the reach of ordinary variables .
Pass object reference
Let's consider the advantages of object references : An object reference is a variable , So you can pass it like a normal variable , Including passing it to another form ; meanwhile , Object reference is more than just a variable , It can have its own properties 、 event 、 Method —— This means that you are even free to add as many custom attributes to it as you like !
Now let's do a wonderful experiment :
1、 Create a form Form1, Put... On the form 3 Textboxes Text1, Text2, Text3、 One Custom object Custom1、 A command button cmdTransObj, In the command button Click Put the following code into the event :
Do form form2 with this.Custom1
Thisform.Refresh()
2、 Create a schema form Form2( Put the... Of the form WindowType Property is set to “1— Pattern ”), Like form 1 Put it that way 3 Textboxes , Create a custom attribute for the form oFrm1Cust, In the form of
Init Enter the following code in the event :
PARAMETER oCustom
This.oFrm1Cust = oCustom
WITH this
.Text1.Value = . oFrm1Cust.parent.Text1.Value
.Text2.Value = . oFrm1Cust.parent.Text2.Value
.Text3.Value = . oFrm1Cust.parent.Text3.Value
ENDWITH
3、 stay Form2 Add a command button to the cmdReturn, Put the following code :
WITH THISFORM
. oFrm1Cust.parent.Text1.Value = .Text1.Value
. oFrm1Cust.parent.Text2.Value = .Text2.Value
. oFrm1Cust.parent.Text3.Value = .Text3.Value
ENDWITH
THISFORM.Release
OK, Now run Form1, Enter some data in each of the three text boxes , Then press the command button . Forms 1 The data on is now transferred to the form 2 In the three text boxes of , Now put the form 2 Change the data inside , Then press the command button CmdReturn, Forms 2 The changes made in are reflected in the form 1 In the !
You can use this method to easily pass multiple data between forms , And because the data referenced by the object can be modified directly in the called form , You don't even need to return any parameters —— Consider the difficulty of returning an array from a form 、 From one to the other CreateObject( Form class ) Cannot return parameters in the form created by the method of —— You can totally believe : This is the best magic !
More information http://www.sn58.cn
边栏推荐
- 基于C语言的图书信息管理系统 课程论文+代码及可执行exe文件
- Translation of meisai C topic in 2022 + sharing of ideas
- 基於Minifilter框架的雙緩沖透明加解密驅動 課程論文+項目源碼
- CFCA安心签接入
- Spark tuning tool -- detailed explanation of sparklens
- 基于SSH的高校实验室物品管理信息系统的设计与实现 论文文档+项目源码及数据库文件
- Wait (), notify (), notifyAll (), sleep (), condition, await (), signal()
- Niuke.com: Candy distribution
- 揭秘GaussDB(for Redis):全面对比Codis
- Whole process of web page request
猜你喜欢
4 life distributions
Source code analysis of AQS & reentrantlock
分享7个神仙壁纸网站,让新的壁纸,给自己小小的雀跃,不陷入年年日日的重复。
Spark history server and event log details
牛客网:主持人调度
ThingsPanel 發布物聯網手機客戶端(多圖)
记一次给OpenHarmony提交代码的过程
Capacity expansion mechanism of Dict Of redis (rehash)
Detailed explanation of Flink checkpoint specific operation process and summary of error reporting and debugging methods
Redis6笔记02 配置文件,发布和订阅,新数据类型,Jedis操作
随机推荐
Handler、Message、Looper、MessageQueue
Semaphore source code analysis
Comparable的使用(用于Arrays.sort)
Countdownlatch source code analysis
Whole process of web page request
牛客网:主持人调度
手机上股票开户安全吗?找谁可以开户啊?
Application of analytic hierarchy process in college teaching evaluation system (principle + example + tool)
Double buffer transparent encryption and decryption driven course paper + project source code based on minifilter framework
分享7个神仙壁纸网站,让新的壁纸,给自己小小的雀跃,不陷入年年日日的重复。
Record the process of submitting code to openharmony once
剑指 Offer II 091. 粉刷房子 : 状态机 DP 运用题
Is industrial securities a state-owned enterprise? Is it safe to open an account in industrial securities?
客从何处来
客户经理的开户二维码开户买股票安全吗?有谁知道啊
基於Minifilter框架的雙緩沖透明加解密驅動 課程論文+項目源碼
揭秘GaussDB(for Redis):全面对比Codis
Niuke.com: Candy distribution
基于Minifilter框架的双缓冲透明加解密驱动 课程论文+项目源码
Design and implementation of university laboratory goods management information system based on SSH